diff --git a/toml/get.hpp b/toml/get.hpp index 0dd6284..e42fa02 100644 --- a/toml/get.hpp +++ b/toml/get.hpp @@ -198,24 +198,24 @@ get(const basic_value& v) // ============================================================================ // forward declaration to use this recursively. ignore this and go ahead. -// array-like type with resize(N) method +// array-like type with push_back(value) method template class M, template class V> detail::enable_if_t, // T is container - detail::has_resize_method, // T::resize(N) works - detail::negation< // but not toml::array + detail::is_container, // T is a container + detail::has_push_back_method, // T::push_back(value) works + detail::negation< // but not toml::array detail::is_exact_toml_type>> >::value, T> get(const basic_value&); -// array-like type with resize(N) method +// array-like type without push_back(value) method template class M, template class V> detail::enable_if_t, // T is container - detail::negation>, // no T::resize() exists - detail::negation< // not toml::array + detail::is_container, // T is a container + detail::negation>, // w/o push_back(...) + detail::negation< // not toml::array detail::is_exact_toml_type>> >::value, T> get(const basic_value&); @@ -274,31 +274,54 @@ get(const basic_value&); template class M, template class V> detail::enable_if_t, // T is container - detail::has_resize_method, // T::resize(N) works - detail::negation< // but not toml::array + detail::is_container, // T is a container + detail::has_push_back_method, // container.push_back(elem) works + detail::negation< // but not toml::array detail::is_exact_toml_type>> >::value, T> get(const basic_value& v) { using value_type = typename T::value_type; - const auto& ar = v.as_array(); + const auto& ary = v.as_array(); + T container; - container.resize(ar.size()); - std::transform(ar.cbegin(), ar.cend(), container.begin(), - [](const value& x){return ::toml::get(x);}); + try_reserve(container, ary.size()); + + for(const auto& elem : ary) + { + container.push_back(get(elem)); + } return container; } // ============================================================================ -// array-like types; but does not have resize(); most likely std::array. +// std::forward_list does not have push_back, insert, or emplace. +// It has insert_after, emplace_after, push_front. + +template class M, template class V> +detail::enable_if_t::value, T> +get(const basic_value& v) +{ + using value_type = typename T::value_type; + T container; + for(const auto& elem : v.as_array()) + { + container.push_front(get(elem)); + } + container.reverse(); + return container; +} + +// ============================================================================ +// array-like types, without push_back(). most likely [std|boost]::array. template class M, template class V> detail::enable_if_t, // T is container - detail::negation>, // no T::resize() exists - detail::negation< // but not toml::array + detail::is_container, // T is a container + detail::negation>, // w/o push_back + detail::negation< // T is not toml::array detail::is_exact_toml_type>> >::value, T> get(const basic_value& v)