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