From 162004663fa262345d9f9450f295df6b5e68303f Mon Sep 17 00:00:00 2001 From: Denis Popov Date: Sun, 29 Nov 2026 22:34:17 -0800 Subject: [PATCH] perf(tuple): single-pass O(N) tuple_cat, move_from_tuple fast path, wrap_in_fields, and concat_literals Replace quadratic/cubic compile-time and runtime folds across tuple concatenation, tuple-to-struct reconstruction, field wrapping, and compile-time literal concatenation with single-pass O(N) algorithms: - `internal/tuple/concat.hpp`: replace the left-fold of pairwise `concat_two` calls (Theta(N^3) compile-time, Theta(N^2) runtime moves) with a consteval `(outer, inner)` index table and flat indexed reference table (`TupleRefs`), constructing the result `rfl::Tuple` in one pack expansion with zero intermediate tuples and strictly one move (rvalue) or one copy (all-lvalue) per element. Qualify internal helper calls (`rfl::internal::tuple::get_ref`, `extract_concat_element`, `concat_impl`) to prevent C++20 ADL hijacking by user element namespaces. Also fixes the latent `const Head&` overload bug that previously returned `TupleWrapper` instead of `rfl::Tuple`, and handles 0/1/empty/mixed lvalue+rvalue/move-only tuples cleanly. - `internal/move_from_tuple.hpp`: guard `unflatten_ptr_tuple` with `has_flatten_fields>()` and `flatten_c_arrays` with `has_arrays()`, fast-pathing plain structs directly into aggregate initialization `T{std::move(rfl::get(_t))...}` without pointer tuples or `tuple_cat`. Replace the O(N^2) `IndptrHelper` fold with a consteval prefix-sum `std::array`, fix nested `rfl::Flatten` pointer unwrapping in `calc_flattened_size`, and recurse `flatten_c_arrays` into nested `rfl::Flatten` pointer tuples (covering C-style arrays inside `rfl::Flatten` and C-arrays declared after `rfl::Flatten`; note that the pre-existing `move_from_pointers` limitation remains when a C-array precedes an `rfl::Flatten` field in the same struct, as expanding a preceding C-array shifts indices in `Pointers` relative to `ptr_tuple_t`). - `internal/wrap_in_fields.hpp` + `internal/calc_flattened_size.hpp`: replace recursive parameter-pack peeling and `flattened_ptr_tuple_t` materialization with a consteval `name_offsets` array and a single non-recursive `index_sequence` expansion. - `internal/concat_literals.hpp`: preserve the 0/1/all-single fast paths and replace the general left-fold (which instantiated O(N) intermediate `rfl::Literal` types with O(N^2) NTTP args on structs containing `rfl::Flatten`) with a single-pass `(outer, inner)` index table over flat `LiteralTypeTable` base packs, with qualified `rfl::internal::get_indexed_literal_type` lookups to prevent ADL hijacking. Verified standalone header self-containment (20/20 passed, standard and `-DREFLECT_CPP_C_ARRAYS_OR_INHERITANCE`) and full CTest suite on both Clang 23.1.6 and GCC 13.4.0 with `-DREFLECTCPP_STRICT_WARNINGS=ON` (0 warnings, 782 passed / 1 expected locale skip out of 783). --- include/rfl/internal/calc_flattened_size.hpp | 34 +++ include/rfl/internal/concat_literals.hpp | 98 +++++++-- include/rfl/internal/move_from_tuple.hpp | 218 ++++++++++++------- include/rfl/internal/tuple/concat.hpp | 126 ++++++++--- include/rfl/internal/wrap_in_fields.hpp | 72 +++--- 5 files changed, 388 insertions(+), 160 deletions(-) create mode 100644 include/rfl/internal/calc_flattened_size.hpp diff --git a/include/rfl/internal/calc_flattened_size.hpp b/include/rfl/internal/calc_flattened_size.hpp new file mode 100644 index 000000000..ea0e57dca --- /dev/null +++ b/include/rfl/internal/calc_flattened_size.hpp @@ -0,0 +1,34 @@ +#ifndef RFL_INTERNAL_CALC_FLATTENED_SIZE_HPP_ +#define RFL_INTERNAL_CALC_FLATTENED_SIZE_HPP_ + +#include +#include +#include + +#include "../Tuple.hpp" +#include "is_flatten_field.hpp" +#include "ptr_tuple_t.hpp" + +namespace rfl::internal { + +/// Calculates the flattened field count of a type (recursively for +/// rfl::Flatten). +template +consteval std::size_t calc_flattened_size() { + using U = std::remove_cvref_t>; + if constexpr (is_flatten_field_v) { + using Tuple = ptr_tuple_t< + std::remove_cvref_t>>; + return [](std::index_sequence<_is...>) { + return (std::size_t{0} + ... + + calc_flattened_size< + tuple_element_t(_is), Tuple>>()); + }(std::make_index_sequence>{}); + } else { + return 1; + } +} + +} // namespace rfl::internal + +#endif diff --git a/include/rfl/internal/concat_literals.hpp b/include/rfl/internal/concat_literals.hpp index 8f1cbbe2a..ed90dedd5 100644 --- a/include/rfl/internal/concat_literals.hpp +++ b/include/rfl/internal/concat_literals.hpp @@ -1,44 +1,102 @@ #ifndef RFL_INTERNAL_CONCATLITERALS_HPP_ #define RFL_INTERNAL_CONCATLITERALS_HPP_ +#include +#include +#include + #include "../Literal.hpp" #include "StringLiteral.hpp" namespace rfl::internal { -// We don't want the operator+ to apply to normal literals, -// so we introduce this wrapper. -template -struct LiteralWrapper { - Literal<_names...> literal_; +struct ConcatLiteralIndex { + std::size_t outer; + std::size_t inner; }; -template -consteval auto wrap_literal(const Literal<_names...>& _literal) { - return LiteralWrapper<_names...>{_literal}; +template +consteval auto calc_concat_literal_indices() { + constexpr std::size_t total = (std::size_t{0} + ... + _sizes); + std::array indices{}; + constexpr std::array sizes{_sizes...}; + std::size_t pos = 0; + for (std::size_t outer = 0; outer < sizeof...(_sizes); ++outer) { + for (std::size_t inner = 0; inner < sizes[outer]; ++inner) { + indices[pos++] = ConcatLiteralIndex{outer, inner}; + } + } + return indices; } -template -consteval auto operator+(const LiteralWrapper<_names1...>&, - const LiteralWrapper<_names2...>&) { - return LiteralWrapper<_names1..., _names2...>{ - rfl::Literal<_names1..., _names2...>()}; +template +struct IndexedLiteralType {}; + +template +T get_indexed_literal_type(IndexedLiteralType<_i, T>); + +template +struct LiteralTypeTable; + +template +struct LiteralTypeTable, Ts...> + : IndexedLiteralType<_is, Ts>... {}; + +template +struct LiteralToTable; + +template +struct LiteralToTable> { + using Table = + LiteralTypeTable, + rfl::LiteralHelper<_names>...>; +}; + +template +consteval auto concat_literals_impl(std::index_sequence<_sizes...>, + std::index_sequence<_ks...>) { + constexpr auto indices = calc_concat_literal_indices<_sizes...>(); + return rfl::Literal( + rfl::internal::get_indexed_literal_type( + std::declval())))::name_...>(); } -template -consteval auto concat_literals(const Head& _head, const Tail&... _tail) { - return (wrap_literal(_head) + ... + wrap_literal(_tail)).literal_; +// Special case - no literals. +consteval inline auto concat_literals() { return rfl::Literal<>(); } + +// Special case - single literal. +template +consteval auto concat_literals(const rfl::Literal<_names...>&) { + return rfl::Literal<_names...>(); } // Special case - every literal contains exactly one value. -template +template consteval auto concat_literals(const rfl::Literal<_head>&, + const rfl::Literal<_second>&, const rfl::Literal<_tail>&...) { - return rfl::Literal<_head, _tail...>(); + return rfl::Literal<_head, _second, _tail...>(); } -// Special case - no literals. -consteval inline auto concat_literals() { return rfl::Literal<>(); } +// General case - arbitrary mix of empty, single, and multi-value literals. +template +consteval auto concat_literals(const Head&, const Second&, const Tail&...) { + constexpr std::size_t total = + Head::size() + Second::size() + (std::size_t{0} + ... + Tail::size()); + if constexpr (total == 0) { + return rfl::Literal<>(); + } else { + using OuterTable = LiteralTypeTable< + std::make_index_sequence<2 + sizeof...(Tail)>, + typename LiteralToTable::Table, + typename LiteralToTable::Table, + typename LiteralToTable::Table...>; + return concat_literals_impl( + std::index_sequence{}, + std::make_index_sequence{}); + } +} } // namespace rfl::internal diff --git a/include/rfl/internal/move_from_tuple.hpp b/include/rfl/internal/move_from_tuple.hpp index c5edf9043..1c73c60f1 100644 --- a/include/rfl/internal/move_from_tuple.hpp +++ b/include/rfl/internal/move_from_tuple.hpp @@ -2,54 +2,35 @@ #define RFL_MOVE_FROM_TUPLE_HPP_ #include +#include +#include #include +#include #include "../Tuple.hpp" +#include "../apply.hpp" #include "../tuple_cat.hpp" #include "Array.hpp" +#include "calc_flattened_size.hpp" #include "has_arrays.hpp" #include "has_flatten_fields.hpp" #include "is_flatten_field.hpp" #include "ptr_tuple_t.hpp" #include "tup_to_ptr_tuple.hpp" -#include "tuple_t.hpp" namespace rfl::internal { -/** - * Calculates the flattened size of a tuple. - * @tparam T The type to calculate the size for. - * @return The flattened size. - */ -template -consteval size_t calc_flattened_size() { - if constexpr (is_flatten_field_v) { - using Tuple = ptr_tuple_t; - return [&](std::integer_sequence) { - return (calc_flattened_size>() + ...); - }(std::make_integer_sequence>()); - } else { - return 1; +template +consteval auto calc_indptr_from_sizes() { + std::array indptr{}; + indptr[0] = _begin; + constexpr std::array sizes{_sizes...}; + for (std::size_t i = 0; i < sizeof...(_sizes); ++i) { + indptr[i + 1] = indptr[i] + sizes[i]; } + return indptr; } -/** - * Helper struct for calculating the indptr array. - * @tparam _head The head of the indptr array. - * @tparam _tail The tail of the indptr array. - */ -template -struct IndptrHelper { - using ArrayType = std::array; - static constexpr auto indptr_ = ArrayType{_head, _tail...}; - - template - consteval auto operator+(const IndptrHelper<_is...>& _other) const { - constexpr auto last = std::get(indptr_); - return IndptrHelper<_head, _tail..., (last + _is)...>{}; - } -}; - /** * Calculates the indptr array for a tuple. * The indptr array is used to map the flattened tuple back to the original @@ -58,49 +39,94 @@ struct IndptrHelper { * @tparam _begin The starting index for the indptr. * @return The indptr array. */ -template +template consteval auto calc_indptr() { - return [&](std::integer_sequence) { - return (IndptrHelper<_begin>{} + ... + - IndptrHelper>()>{}) - .indptr_; - }(std::make_integer_sequence>()); + constexpr std::size_t size = rfl::tuple_size_v>; + if constexpr (size == 0) { + return std::array{_begin}; + } else { + return [](std::index_sequence<_is...>) { + return calc_indptr_from_sizes< + _begin, calc_flattened_size< + tuple_element_t(_is), Tuple>>()...>(); + }(std::make_index_sequence{}); + } +} + +template +auto unflatten_ptr_tuple(PtrTupleType& _t); + +template +auto unflatten_one(PtrTupleType& _t) { + using T = std::remove_cvref_t(_i), TargetTupleType>>>; + + if constexpr (is_flatten_field_v) { + using SubTargetTupleType = ptr_tuple_t< + std::remove_cvref_t>>; + + return unflatten_ptr_tuple(_t); + + } else { + return rfl::get(_j)>(_t); + } +} + +template +auto unflatten_ptr_tuple_impl(PtrTupleType&, std::index_sequence<>) { + return rfl::Tuple<>(); +} + +template +auto unflatten_ptr_tuple_impl(PtrTupleType& _t, std::index_sequence<_is...>) { + constexpr auto indptr = calc_indptr(); + return rfl::make_tuple( + unflatten_one(_t)...); } /** - * Unflattens a tuple of pointers into a target tuple. T - * This is meant for when the uses uses rfl::Flatten<...>. + * Unflattens a tuple of pointers into a target tuple. + * This is meant for when the user uses rfl::Flatten<...>. * @param _t Tuple of pointers to elements. * @return A tuple with unflattened elements. */ -template +template auto unflatten_ptr_tuple(PtrTupleType& _t) { constexpr auto size = rfl::tuple_size_v>; + return unflatten_ptr_tuple_impl( + _t, std::make_index_sequence{}); +} - constexpr auto indptr = calc_indptr(); +template +auto move_from_pointers(Pointers&& _ptrs); - const auto unflatten_one = - [&](std::integral_constant) { - using T = std::remove_cvref_t< - std::remove_pointer_t>>; +template +auto move_one_from_pointers(Pointers& _ptrs) { + using FieldType = tuple_element_t(_i), Pointers>; - constexpr size_t j = std::get<_i>(indptr); + if constexpr (std::is_pointer_v) { + return std::move(*rfl::get(_i)>(_ptrs)); - if constexpr (is_flatten_field_v) { - using SubTargetTupleType = - ptr_tuple_t>; + } else { + using PtrTupleType = ptr_tuple_t>; - return unflatten_ptr_tuple(_t); + using U = std::remove_cvref_t(_i), PtrTupleType>>::Type>; - } else { - return std::get(_t); - } - }; + return move_from_pointers(rfl::get(_i)>(_ptrs)); + } +} + +template +auto move_from_pointers_impl(Pointers&, std::index_sequence<>) { + return std::remove_cvref_t{}; +} - return [&](std::integer_sequence) { - return rfl::make_tuple( - unflatten_one(std::integral_constant{})...); - }(std::make_integer_sequence()); +template +auto move_from_pointers_impl(Pointers& _ptrs, std::index_sequence<_is...>) { + return std::remove_cvref_t{move_one_from_pointers(_ptrs)...}; } /** @@ -110,32 +136,19 @@ auto unflatten_ptr_tuple(PtrTupleType& _t) { */ template auto move_from_pointers(Pointers&& _ptrs) { - const auto move_one = [&](std::integral_constant) { - using FieldType = tuple_element_t<_i, std::remove_cvref_t>; - - if constexpr (std::is_pointer_v) { - return std::move(*std::get<_i>(_ptrs)); - - } else { - using PtrTupleType = ptr_tuple_t>; - - using U = std::remove_cvref_t>::Type>; - - return move_from_pointers(std::get<_i>(_ptrs)); - } - }; - return [&](std::integer_sequence) { - return std::remove_cvref_t{ - move_one(std::integral_constant{})...}; - }(std::make_integer_sequence>()); + return move_from_pointers_impl( + _ptrs, + std::make_index_sequence< + rfl::tuple_size_v>>{}); } +template +auto flatten_c_arrays(TupleType&& _tup); + /** * Flattens a single element into a tuple. * @param _v Source element. * @return A tuple containing the element. - * */ template auto flatten_array(T* _v) { @@ -173,17 +186,38 @@ auto make_tuple_from_element(Array* _arr) { return flatten_array(&(_arr->arr_)); } +/** + * Recursively flattens C-style arrays inside a nested unflattened tuple. + * @param _tup Nested pointer tuple from an rfl::Flatten field. + * @return A single-element tuple wrapping the flattened nested tuple. + */ +template +auto make_tuple_from_element(rfl::Tuple _tup) { + return rfl::make_tuple(flatten_c_arrays(std::move(_tup))); +} + /** * Flattens C-style arrays in a tuple. * @param _tup Source tuple. * @return A flattened tuple. */ -auto flatten_c_arrays(auto&& _tup) { +template +auto flatten_c_arrays(TupleType&& _tup) { return rfl::apply( [](auto... _v) { return rfl::tuple_cat(make_tuple_from_element(_v)...); }, _tup); } +template +auto move_from_tuple_direct(TupleType&, std::index_sequence<>) { + return T{}; +} + +template +auto move_from_tuple_direct(TupleType& _t, std::index_sequence<_is...>) { + return T{std::move(rfl::get(_is)>(_t))...}; +} + /** * Moves elements from a tuple to a target object. * @param _t Source tuple. @@ -191,10 +225,26 @@ auto flatten_c_arrays(auto&& _tup) { */ template auto move_from_tuple(TupleType&& _t) { - using TargetTupleType = tuple_t>; - auto ptr_tuple = tup_to_ptr_tuple(_t); - return move_from_pointers( - flatten_c_arrays(unflatten_ptr_tuple(ptr_tuple))); + using TargetType = std::remove_cvref_t; + using TargetPtrTupleType = ptr_tuple_t; + constexpr bool has_flatten = has_flatten_fields(); + constexpr bool has_c_arrays = has_arrays>(); + if constexpr (!has_flatten && !has_c_arrays) { + return move_from_tuple_direct( + _t, std::make_index_sequence< + rfl::tuple_size_v>>{}); + } else { + auto ptr_tuple = tup_to_ptr_tuple(_t); + if constexpr (has_flatten && has_c_arrays) { + return move_from_pointers( + flatten_c_arrays(unflatten_ptr_tuple(ptr_tuple))); + } else if constexpr (has_flatten) { + return move_from_pointers( + unflatten_ptr_tuple(ptr_tuple)); + } else { + return move_from_pointers(flatten_c_arrays(ptr_tuple)); + } + } } } // namespace rfl::internal diff --git a/include/rfl/internal/tuple/concat.hpp b/include/rfl/internal/tuple/concat.hpp index 3020a000b..38c695a4a 100644 --- a/include/rfl/internal/tuple/concat.hpp +++ b/include/rfl/internal/tuple/concat.hpp @@ -1,54 +1,120 @@ #ifndef RFL_INTERNAL_TUPLE_CONCAT_HPP_ #define RFL_INTERNAL_TUPLE_CONCAT_HPP_ +#include +#include +#include #include #include "../../Tuple.hpp" namespace rfl::internal::tuple { -template -struct TupleWrapper { - rfl::Tuple tuple_; +template +inline constexpr bool is_rfl_tuple_v = false; + +template +inline constexpr bool is_rfl_tuple_v> = true; + +template +inline constexpr bool is_movable_non_empty_tuple_v = + (rfl::tuple_size_v > 0) && !std::is_lvalue_reference_v && + !std::is_const_v>; + +struct ConcatIndex { + std::size_t outer; + std::size_t inner; +}; + +template +consteval auto calc_concat_indices() { + constexpr std::size_t total = (std::size_t{0} + ... + _sizes); + std::array indices{}; + constexpr std::array sizes{_sizes...}; + std::size_t pos = 0; + for (std::size_t outer = 0; outer < sizeof...(_sizes); ++outer) { + for (std::size_t inner = 0; inner < sizes[outer]; ++inner) { + indices[pos++] = ConcatIndex{outer, inner}; + } + } + return indices; +} + +template +struct IndexedRef { + T&& ref_; +}; + +template +struct TupleRefs; + +template +struct TupleRefs, Ts...> : IndexedRef<_is, Ts>... { + constexpr explicit TupleRefs(Ts&&... _ts) noexcept + : IndexedRef<_is, Ts>{std::forward(_ts)}... {} }; -template -auto wrap_tuple(const rfl::Tuple& _tuple) { - return TupleWrapper{_tuple}; +template +constexpr T&& get_ref(IndexedRef<_i, T>& _r) noexcept { + return std::forward(_r.ref_); } -template -auto wrap_tuple(rfl::Tuple&& _tuple) { - return TupleWrapper{std::forward >(_tuple)}; +template +decltype(auto) extract_concat_element(Refs& _refs) { + auto&& tup = rfl::internal::tuple::get_ref<_outer>(_refs); + if constexpr (_all_copy) { + return rfl::get(_inner)>(tup); + } else { + using TupRef = decltype(rfl::internal::tuple::get_ref<_outer>(_refs)); + constexpr bool can_move = + !std::is_lvalue_reference_v && + !std::is_const_v>; + if constexpr (can_move) { + return std::move(rfl::get(_inner)>(tup)); + } else { + using ElemType = rfl::tuple_element_t(_inner), TupRef>; + return ElemType(rfl::get(_inner)>(tup)); + } + } } -template -auto concat_two(rfl::Tuple&& _t1, rfl::Tuple&& _t2, - std::integer_sequence, - std::integer_sequence) { - return rfl::Tuple(std::move(rfl::get<_is>(_t1))..., - std::move(rfl::get<_js>(_t2))...); +template +auto concat_impl(Refs& _refs, std::index_sequence<_sizes...>, + std::index_sequence<_ks...>) { + constexpr auto indices = calc_concat_indices<_sizes...>(); + return rfl::Tuple(indices[_ks].inner), + decltype(rfl::internal::tuple::get_ref(_refs))>...>( + rfl::internal::tuple::extract_concat_element< + indices[_ks].outer, indices[_ks].inner, _all_copy>(_refs)...); } -template -auto operator+(TupleWrapper&& _t1, TupleWrapper&& _t2) { - return TupleWrapper{ - .tuple_ = - concat_two(std::move(_t1.tuple_), std::move(_t2.tuple_), - std::make_integer_sequence(), - std::make_integer_sequence())}; +template + requires((std::size_t{0} + ... + rfl::tuple_size_v) == 0) +inline auto concat(Tuples&&...) { + return rfl::Tuple<>(); } -template -auto concat(const Head& _head, const Tail&... _tail) { - return (wrap_tuple(_head) + ... + wrap_tuple(_tail)); +template + requires(is_rfl_tuple_v> && rfl::tuple_size_v > 0) +auto concat(T&& _tuple) { + return std::remove_cvref_t(std::forward(_tuple)); } -template -auto concat(Head&& _head, Tail&&... _tail) { - return (wrap_tuple(std::forward(_head)) + ... + - wrap_tuple(std::forward(_tail))) - .tuple_; +template + requires((std::size_t{0} + ... + rfl::tuple_size_v) > 0 && + !(sizeof...(Tuples) == 1 && + (is_rfl_tuple_v> && ...))) +auto concat(Tuples&&... _tuples) { + constexpr bool all_copy = + !(false || ... || is_movable_non_empty_tuple_v); + TupleRefs, Tuples...> refs( + std::forward(_tuples)...); + return rfl::internal::tuple::concat_impl( + refs, std::index_sequence...>{}, + std::make_index_sequence< + (std::size_t{0} + ... + rfl::tuple_size_v)>{}); } } // namespace rfl::internal::tuple diff --git a/include/rfl/internal/wrap_in_fields.hpp b/include/rfl/internal/wrap_in_fields.hpp index 1321d208f..0f21ddd6a 100644 --- a/include/rfl/internal/wrap_in_fields.hpp +++ b/include/rfl/internal/wrap_in_fields.hpp @@ -1,45 +1,65 @@ #ifndef RFL_INTERNAL_WRAP_IN_FIELDS_HPP_ #define RFL_INTERNAL_WRAP_IN_FIELDS_HPP_ +#include +#include #include +#include #include "../Tuple.hpp" #include "../make_field.hpp" -#include "flattened_ptr_tuple_t.hpp" +#include "calc_flattened_size.hpp" #include "is_flatten_field.hpp" #include "lit_name.hpp" namespace rfl::internal { -// TODO: Non-recursive implementation -template -auto wrap_in_fields(auto&& _tuple, Fields&&... _fields) { - constexpr auto size = - rfl::tuple_size_v>; - constexpr auto i = sizeof...(_fields); - if constexpr (i == size) { - return rfl::make_tuple(std::move(_fields)...); +template +consteval auto calc_field_name_offsets() { + std::array offsets{}; + constexpr std::array sizes{_sizes...}; + std::size_t offset = 0; + for (std::size_t i = 0; i < sizeof...(_sizes); ++i) { + offsets[i] = static_cast(offset); + offset += sizes[i]; + } + return offsets; +} + +template +auto wrap_one_in_field(TupleType& _tuple) { + using Elem = tuple_element_t(_i), TupleType>; + using Type = std::remove_cvref_t>; + if constexpr (is_flatten_field_v) { + return std::move(rfl::get(_i)>(_tuple)); } else { - auto value = std::move(std::get(_tuple)); - using Type = std::remove_cvref_t>; - if constexpr (is_flatten_field_v) { - // The problem here is that the FieldNames are already flattened, but this - // is not, so we need to determine how many field names to skip. - constexpr auto n_skip = rfl::tuple_size_v< - std::remove_cvref_t>>; - return wrap_in_fields( - std::move(_tuple), std::move(_fields)..., std::move(value)); - } else { - const auto name_literal = FieldNames::template name_of(); - auto new_field = rfl::make_field< - lit_name_v>>( - std::move(value)); - return wrap_in_fields( - std::move(_tuple), std::move(_fields)..., std::move(new_field)); - } + constexpr auto name_literal = FieldNames::template name_of<_name_idx>(); + return rfl::make_field< + lit_name_v>>( + std::move(rfl::get(_i)>(_tuple))); } } +template +auto wrap_in_fields_impl(TupleType&, std::index_sequence<>) { + return rfl::Tuple<>(); +} + +template +auto wrap_in_fields_impl(TupleType& _tuple, std::index_sequence<_is...>) { + constexpr auto offsets = calc_field_name_offsets(_is), TupleType>>()...>(); + return rfl::make_tuple( + wrap_one_in_field(_tuple)...); +} + +template +auto wrap_in_fields(TupleType&& _tuple) { + using RawTuple = std::remove_cvref_t; + return wrap_in_fields_impl( + _tuple, std::make_index_sequence>{}); +} + } // namespace rfl::internal #endif