|
6 | 6 |
|
7 | 7 | #include "rfl/field_names_t.hpp" |
8 | 8 | #include "rfl/internal/bind_to_tuple.hpp" |
9 | | -#include "rfl/internal/flattened_ptr_tuple_t.hpp" |
10 | 9 | #include "rfl/internal/has_fields.hpp" |
11 | | -#include "rfl/internal/is_flatten_field.hpp" |
12 | 10 | #include "rfl/internal/is_named_tuple.hpp" |
13 | | -#include "rfl/internal/lit_name.hpp" |
| 11 | +#include "rfl/internal/wrap_in_fields.hpp" |
14 | 12 |
|
15 | 13 | namespace rfl { |
16 | 14 | namespace internal { |
17 | 15 |
|
18 | | -template <class FieldNames, int j = 0, class... Fields> |
19 | | -auto wrap_in_fields(auto&& _tuple, Fields&&... _fields) { |
20 | | - constexpr auto size = std::tuple_size_v<std::decay_t<decltype(_tuple)>>; |
21 | | - constexpr auto i = sizeof...(_fields); |
22 | | - if constexpr (i == size) { |
23 | | - return std::make_tuple(std::move(_fields)...); |
24 | | - } else { |
25 | | - auto value = std::move(std::get<i>(_tuple)); |
26 | | - using Type = std::decay_t<decltype(value)>; |
27 | | - if constexpr (is_flatten_field_v<Type>) { |
28 | | - // The problem here is that the FieldNames are already flattened, but this |
29 | | - // is not, so we need to determine how many field names to skip. |
30 | | - constexpr auto n_skip = std::tuple_size_v< |
31 | | - std::decay_t<flattened_ptr_tuple_t<typename Type::Type>>>; |
32 | | - return wrap_in_fields<FieldNames, j + n_skip>( |
33 | | - std::move(_tuple), std::move(_fields)..., std::move(value)); |
34 | | - } else { |
35 | | - const auto name_literal = FieldNames::template name_of<j>(); |
36 | | - auto new_field = |
37 | | - rfl::make_field<lit_name_v<std::decay_t<decltype(name_literal)>>>( |
38 | | - std::move(value)); |
39 | | - return wrap_in_fields<FieldNames, j + 1>( |
40 | | - std::move(_tuple), std::move(_fields)..., std::move(new_field)); |
41 | | - } |
42 | | - } |
43 | | -} |
44 | | - |
45 | 16 | template <class OriginalStruct> |
46 | 17 | auto move_to_field_tuple(OriginalStruct&& _t) { |
47 | 18 | using T = std::decay_t<OriginalStruct>; |
48 | | - if constexpr (internal::is_named_tuple_v<T>) { |
| 19 | + if constexpr (is_named_tuple_v<T>) { |
49 | 20 | return _t.fields(); |
50 | 21 | } else if constexpr (has_fields<T>()) { |
51 | 22 | return bind_to_tuple(_t, [](auto& x) { return std::move(x); }); |
|
0 commit comments