From 382e3dc3ab3ea26ba8567f3ecd84b476afcec44a Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Wed, 14 Oct 2020 22:27:29 +0900 Subject: [PATCH] refactor: use serializer::is_array_of_tables --- toml/serializer.hpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/toml/serializer.hpp b/toml/serializer.hpp index cf47710..433997b 100644 --- a/toml/serializer.hpp +++ b/toml/serializer.hpp @@ -248,13 +248,7 @@ struct serializer { return std::string("[]"); } - - // Since TOML v0.5.0, heterogeneous arrays are allowed. So we need to - // check all the element in an array to check if the array is an array - // of tables. - const bool is_array_of_tables = std::all_of(v.begin(), v.end(), - [](const value_type& elem) {return elem.is_table();}); - if(is_array_of_tables) + if(this->is_array_of_tables(v)) { // if it's not inlined, we need to add `[[table.key]]`. // but if it can be inlined, @@ -674,8 +668,16 @@ struct serializer bool is_array_of_tables(const value_type& v) const { if(!v.is_array()) {return false;} - const auto& a = v.as_array(); - return !a.empty() && a.front().is_table(); + return is_array_of_tables(v.as_array()); + } + bool is_array_of_tables(const array_type& v) const + { + // Since TOML v0.5.0, heterogeneous arrays are allowed. So we need to + // check all the element in an array to check if the array is an array + // of tables. + return std::all_of(v.begin(), v.end(), [](const value_type& elem) { + return elem.is_table(); + }); } private: