@@ -85,27 +85,29 @@ class NamedTuple {
85
85
// / Move constructor.
86
86
template <class ... OtherFieldTypes>
87
87
NamedTuple (NamedTuple<OtherFieldTypes...>&& _other)
88
- : NamedTuple(retrieve_fields(_other.fields(), seq_)) {}
88
+ : NamedTuple(retrieve_fields(
89
+ std::forward<NamedTuple<OtherFieldTypes...>>(_other).fields(),
90
+ seq_)) {}
89
91
90
92
~NamedTuple () = default ;
91
93
92
94
// / Returns a new named tuple with additional fields.
93
95
template <internal::StringLiteral _name, class FType , class ... Tail>
94
- auto add (Field<_name, FType>&& _head, Tail&&... _tail) {
96
+ auto add (Field<_name, FType>&& _head, Tail&&... _tail) && {
95
97
using Head = Field<_name, FType>;
96
98
if constexpr (sizeof ...(Tail) > 0 ) {
97
99
return NamedTuple<FieldTypes..., std::remove_cvref_t <Head>>(
98
- make_fields (seq_, std::forward<Head>(_head)))
100
+ std::move (* this ). make_fields (seq_, std::forward<Head>(_head)))
99
101
.add (std::forward<Tail>(_tail)...);
100
102
} else {
101
103
return NamedTuple<FieldTypes..., std::remove_cvref_t <Head>>(
102
- make_fields (seq_, std::forward<Head>(_head)));
104
+ std::move (* this ). make_fields (seq_, std::forward<Head>(_head)));
103
105
}
104
106
}
105
107
106
108
// / Returns a new named tuple with additional fields.
107
109
template <internal::StringLiteral _name, class FType , class ... Tail>
108
- auto add (Field<_name, FType> _head, const Tail&... _tail) const {
110
+ auto add (Field<_name, FType> _head, const Tail&... _tail) const & {
109
111
using Head = Field<_name, FType>;
110
112
if constexpr (sizeof ...(Tail) > 0 ) {
111
113
return NamedTuple<FieldTypes..., std::remove_cvref_t <Head>>(
@@ -120,19 +122,21 @@ class NamedTuple {
120
122
// / Template specialization for rfl::Tuple, so we can pass fields from other
121
123
// / named tuples.
122
124
template <class ... TupContent, class ... Tail>
123
- auto add (rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) {
125
+ auto add (rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) && {
124
126
if constexpr (sizeof ...(Tail) > 0 ) {
125
- return add_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple))
127
+ return std::move (*this )
128
+ .add_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple))
126
129
.add (std::forward<Tail>(_tail)...);
127
130
} else {
128
- return add_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple));
131
+ return std::move (*this ).add_tuple (
132
+ std::forward<rfl::Tuple<TupContent...>>(_tuple));
129
133
}
130
134
}
131
135
132
136
// / Template specialization for rfl::Tuple, so we can pass fields from other
133
137
// / named tuples.
134
138
template <class ... TupContent, class ... Tail>
135
- auto add (rfl::Tuple<TupContent...> _tuple, const Tail&... _tail) const {
139
+ auto add (rfl::Tuple<TupContent...> _tuple, const Tail&... _tail) const & {
136
140
if constexpr (sizeof ...(Tail) > 0 ) {
137
141
return add_tuple (std::move (_tuple)).add (_tail...);
138
142
} else {
@@ -143,15 +147,18 @@ class NamedTuple {
143
147
// / Template specialization for NamedTuple, so we can pass fields from other
144
148
// / named tuples.
145
149
template <class ... TupContent, class ... Tail>
146
- auto add (NamedTuple<TupContent...>&& _named_tuple, Tail&&... _tail) {
147
- return add (std::forward<rfl::Tuple<TupContent...>>(_named_tuple.fields ()),
148
- std::forward<Tail>(_tail)...);
150
+ auto add (NamedTuple<TupContent...>&& _named_tuple, Tail&&... _tail) && {
151
+ return std::move (*this ).add (
152
+ std::forward<rfl::Tuple<TupContent...>>(
153
+ std::forward<NamedTuple<TupContent...>>(_named_tuple).fields ()),
154
+ std::forward<Tail>(_tail)...);
149
155
}
150
156
151
157
// / Template specialization for NamedTuple, so we can pass fields from other
152
158
// / named tuples.
153
159
template <class ... TupContent, class ... Tail>
154
- auto add (NamedTuple<TupContent...> _named_tuple, const Tail&... _tail) const {
160
+ auto add (NamedTuple<TupContent...> _named_tuple,
161
+ const Tail&... _tail) const & {
155
162
return add (_named_tuple.fields (), _tail...);
156
163
}
157
164
@@ -193,10 +200,10 @@ class NamedTuple {
193
200
}
194
201
195
202
// / Returns a tuple containing the fields.
196
- Fields fields () { return make_fields (seq_); }
203
+ Fields fields () && { return std::move (* this ). make_fields (seq_); }
197
204
198
205
// / Returns a tuple containing the fields.
199
- Fields fields () const { return make_fields (seq_); }
206
+ Fields fields () const & { return make_fields (seq_); }
200
207
201
208
// / Gets a field by index.
202
209
template <int _index>
@@ -383,17 +390,17 @@ class NamedTuple {
383
390
// / Adds the elements of a tuple to a newly created named tuple,
384
391
// / and other elements to a newly created named tuple.
385
392
template <class ... TupContent>
386
- constexpr auto add_tuple (rfl::Tuple<TupContent...>&& _tuple) {
393
+ constexpr auto add_tuple (rfl::Tuple<TupContent...>&& _tuple) && {
387
394
const auto a = [this ](auto &&... _fields) {
388
- return this -> add (std::forward<TupContent>(_fields)...);
395
+ return std::move (* this ). add (std::forward<TupContent>(_fields)...);
389
396
};
390
397
return rfl::apply (a, std::forward<rfl::Tuple<TupContent...>>(_tuple));
391
398
}
392
399
393
400
// / Adds the elements of a tuple to a newly created named tuple,
394
401
// / and other elements to a newly created named tuple.
395
402
template <class ... TupContent>
396
- constexpr auto add_tuple (rfl::Tuple<TupContent...>&& _tuple) const {
403
+ constexpr auto add_tuple (rfl::Tuple<TupContent...>&& _tuple) const & {
397
404
const auto a = [this ](auto &&... _fields) {
398
405
return this ->add (std::forward<TupContent>(_fields)...);
399
406
};
@@ -435,11 +442,10 @@ class NamedTuple {
435
442
// / Generates the fields.
436
443
template <int ... _is, class ... AdditionalArgs>
437
444
auto make_fields (std::integer_sequence<int , _is...>,
438
- AdditionalArgs&&... _args) {
445
+ AdditionalArgs&&... _args) && {
439
446
const auto wrap = [this ]<int _i>(Index<_i>) {
440
447
using FieldType = internal::nth_element_t <_i, FieldTypes...>;
441
- using T = std::remove_cvref_t <typename FieldType::Type>;
442
- return FieldType (std::forward<T>(rfl::get<_i>(values_)));
448
+ return FieldType (std::move (rfl::get<_i>(values_)));
443
449
};
444
450
return rfl::make_tuple (wrap (Index<_is>{})...,
445
451
std::forward<AdditionalArgs>(_args)...);
@@ -448,7 +454,7 @@ class NamedTuple {
448
454
// / Generates the fields.
449
455
template <int ... _is, class ... AdditionalArgs>
450
456
auto make_fields (std::integer_sequence<int , _is...>,
451
- AdditionalArgs... _args) const {
457
+ AdditionalArgs... _args) const & {
452
458
const auto wrap = [this ]<int _i>(Index<_i>) {
453
459
using FieldType = internal::nth_element_t <_i, FieldTypes...>;
454
460
return FieldType (rfl::get<_i>(values_));
0 commit comments