Skip to content

Commit 28c602e

Browse files
committed
Remove boilerplate to rfl::internal::to_ptr_field_tuple
Also ensure the same behavioral changes that happened to move/copy_to_field_tuple are actual for to_ptr_field_tuple by wrapping in fields if necessary
1 parent b86d207 commit 28c602e

File tree

4 files changed

+56
-2341
lines changed

4 files changed

+56
-2341
lines changed

include/rfl/internal/move_to_field_tuple.hpp

+2-31
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,17 @@
66

77
#include "rfl/field_names_t.hpp"
88
#include "rfl/internal/bind_to_tuple.hpp"
9-
#include "rfl/internal/flattened_ptr_tuple_t.hpp"
109
#include "rfl/internal/has_fields.hpp"
11-
#include "rfl/internal/is_flatten_field.hpp"
1210
#include "rfl/internal/is_named_tuple.hpp"
13-
#include "rfl/internal/lit_name.hpp"
11+
#include "rfl/internal/wrap_in_fields.hpp"
1412

1513
namespace rfl {
1614
namespace internal {
1715

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-
4516
template <class OriginalStruct>
4617
auto move_to_field_tuple(OriginalStruct&& _t) {
4718
using T = std::decay_t<OriginalStruct>;
48-
if constexpr (internal::is_named_tuple_v<T>) {
19+
if constexpr (is_named_tuple_v<T>) {
4920
return _t.fields();
5021
} else if constexpr (has_fields<T>()) {
5122
return bind_to_tuple(_t, [](auto& x) { return std::move(x); });

include/rfl/internal/ptr_field_tuple_t.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
#include <tuple>
66
#include <type_traits>
77

8-
#include "rfl/internal/is_named_tuple.hpp"
98
#include "rfl/internal/to_ptr_field_tuple.hpp"
109

1110
namespace rfl {
1211
namespace internal {
1312

1413
template <class T>
15-
using ptr_field_tuple_t =
16-
typename std::invoke_result<decltype(to_ptr_field_tuple<T>), T>::type;
14+
using ptr_field_tuple_t = decltype(to_ptr_field_tuple(std::declval<T&>()));
1715

1816
} // namespace internal
1917
} // namespace rfl

0 commit comments

Comments
 (0)