#ifndef RFL_FROM_NAMED_TUPLE_HPP_ #define RFL_FROM_NAMED_TUPLE_HPP_ #include #include "internal/copy_from_named_tuple.hpp" #include "internal/copy_from_tuple.hpp" #include "internal/has_fields.hpp" #include "internal/move_from_named_tuple.hpp" #include "internal/move_from_tuple.hpp" #include "named_tuple_t.hpp" namespace rfl { /// Generates the struct T from a named tuple. template auto from_named_tuple(NamedTupleType&& _n) { using RequiredType = std::remove_cvref_t>; if constexpr (!std::is_same< std::remove_cvref_t, RequiredType>()) { return from_named_tuple(RequiredType(std::forward(_n)) ); } else if constexpr (internal::has_fields()) { if constexpr (std::is_lvalue_reference {}) { return internal::copy_from_named_tuple(_n); } else { return internal::move_from_named_tuple(_n); } } else { if constexpr (std::is_lvalue_reference {}) { return internal::copy_from_tuple(_n.values()); } else { return internal::move_from_tuple(std::move(_n.values())); } } } /// Generates the struct T from a named tuple. template auto from_named_tuple(const NamedTupleType& _n) { using RequiredType = std::remove_cvref_t>; if constexpr (!std::is_same< std::remove_cvref_t, RequiredType>()) { return from_named_tuple(RequiredType(_n)); } else if constexpr (internal::has_fields()) { return internal::copy_from_named_tuple(_n); } else { return internal::copy_from_tuple(_n.values()); } } } // namespace rfl #endif