diff --git a/include/common/array.hpp b/include/common/array.hpp index 3ec8b7c..a8c9cee 100644 --- a/include/common/array.hpp +++ b/include/common/array.hpp @@ -104,6 +104,10 @@ class basic_array size_t Size, template typename fixed_array_t = std::array> fixed_array_t as_fixed_array() const; + template + std::tuple as_tuple() const; + template + std::pair as_pair() const; // Usage: get(key_1, key_2, ..., default_value); template @@ -217,6 +221,11 @@ class basic_array template auto get_helper(const value_t& default_value, size_t pos) const; + template + tuple_t as_tuple_templ() const; + template + void set_tuple(tuple_t& tup) const; + string_t format(size_t indent, size_t indent_times) const; private: @@ -379,6 +388,48 @@ inline fixed_array_t basic_array::as_fixed_array() cons return result; } +template +template +inline void basic_array::set_tuple(tuple_t& tup) const +{ + using elem_t = std::tuple_element_t; + + if constexpr (index > 0) { + set_tuple(tup); + } + + std::get(tup) = static_cast(at(index)); +} + +template +template +inline tuple_t basic_array::as_tuple_templ() const +{ + constexpr size_t tuple_size = std::tuple_size_v; + + if (size() != tuple_size) { + throw exception("Wrong array size"); + } + + tuple_t result; + set_tuple(result); + return result; +} + +template +template +inline std::tuple basic_array::as_tuple() const +{ + return as_tuple_templ>(); +} + +template +template +inline std::pair basic_array::as_pair() const +{ + return as_tuple_templ>(); +} + template template inline auto basic_array::get(key_then_default_value_t&&... keys_then_default_value) const diff --git a/include/common/utils.hpp b/include/common/utils.hpp index e7219b1..fb71ea5 100644 --- a/include/common/utils.hpp +++ b/include/common/utils.hpp @@ -84,6 +84,16 @@ constexpr bool is_collection = false; template constexpr bool is_collection = is_container && !is_map && !is_fixed_array; +template typename Ref, typename = void> +constexpr bool is_specialization = false; +template