#ifndef RFL_INTERNAL_TO_FLATTENED_PTR_TUPLE_HPP_ #define RFL_INTERNAL_TO_FLATTENED_PTR_TUPLE_HPP_ #include #include "has_flatten_fields.hpp" #include "is_flatten_field.hpp" #include "to_ptr_tuple.hpp" namespace rfl { namespace internal { template auto flatten_ptr_tuple(PtrTuple&& _t, Args... _args) { constexpr auto i = sizeof...(Args); if constexpr (i == 0 && !has_flatten_fields()) { return std::forward(_t); } else if constexpr (i == std::tuple_size_v>) { return std::tuple_cat(std::forward(_args)...); } else { using T = std::tuple_element_t>; if constexpr (is_flatten_field_v) { return flatten_ptr_tuple( std::forward(_t), std::forward(_args)..., flatten_ptr_tuple(to_ptr_tuple(std::get(_t)->get()))); } else { return flatten_ptr_tuple(std::forward(_t), std::forward(_args)..., std::make_tuple(std::get(_t))); } } } template auto to_flattened_ptr_tuple(T&& _t) { return flatten_ptr_tuple(to_ptr_tuple(_t)); } } // namespace internal } // namespace rfl #endif