@@ -165,21 +165,21 @@ class NamedTuple {
165
165
// / Creates a new named tuple by applying the supplied function to
166
166
// / field. The function is expected to return a named tuple itself.
167
167
template <typename F>
168
- auto and_then (const F& _f) {
168
+ auto and_then (const F& _f) && {
169
169
const auto transform_field = [&_f](auto ... _fields) {
170
170
return rfl::tuple_cat (_f (std::move (_fields)).fields ()...);
171
171
};
172
172
const auto to_nt = []<class ... NewFields>(rfl::Tuple<NewFields...>&& _tup) {
173
173
return NamedTuple<NewFields...>(_tup);
174
174
};
175
- auto new_fields = rfl::apply (transform_field, std::move (fields () ));
175
+ auto new_fields = rfl::apply (transform_field, std::move (* this ). fields ());
176
176
return to_nt (std::move (new_fields));
177
177
}
178
178
179
179
// / Creates a new named tuple by applying the supplied function to
180
180
// / field. The function is expected to return a named tuple itself.
181
181
template <typename F>
182
- auto and_then (const F& _f) const {
182
+ auto and_then (const F& _f) const & {
183
183
const auto transform_field = [&_f](auto ... _fields) {
184
184
return rfl::tuple_cat (_f (std::move (_fields)).fields ()...);
185
185
};
@@ -283,13 +283,15 @@ class NamedTuple {
283
283
// / Replaces one or several fields, returning a new version
284
284
// / with the non-replaced fields left unchanged.
285
285
template <internal::StringLiteral _name, class FType , class ... OtherRFields>
286
- auto replace (Field<_name, FType>&& _field, OtherRFields&&... _other_fields) {
286
+ auto replace (Field<_name, FType>&& _field,
287
+ OtherRFields&&... _other_fields) && {
287
288
using RField = Field<_name, FType>;
288
289
constexpr auto num_other_fields = sizeof ...(OtherRFields);
289
290
if constexpr (num_other_fields == 0 ) {
290
- return replace_value<RField>(_field.value_ );
291
+ return std::move (* this ). template replace_value <RField>(_field.value_ );
291
292
} else {
292
- return replace_value<RField>(_field.value_ )
293
+ return std::move (*this )
294
+ .template replace_value <RField>(_field.value_ )
293
295
.replace (std::forward<OtherRFields>(_other_fields)...);
294
296
}
295
297
}
@@ -298,7 +300,7 @@ class NamedTuple {
298
300
// / with the non-replaced fields left unchanged.
299
301
template <internal::StringLiteral _name, class FType , class ... OtherRFields>
300
302
auto replace (Field<_name, FType> _field,
301
- const OtherRFields&... _other_fields) const {
303
+ const OtherRFields&... _other_fields) const & {
302
304
using RField = Field<_name, FType>;
303
305
constexpr auto num_other_fields = sizeof ...(OtherRFields);
304
306
if constexpr (num_other_fields == 0 ) {
@@ -312,19 +314,21 @@ class NamedTuple {
312
314
// / Template specialization for rfl::Tuple, so we can pass fields from other
313
315
// / named tuples.
314
316
template <class ... TupContent, class ... Tail>
315
- auto replace (rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) {
317
+ auto replace (rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) && {
316
318
if constexpr (sizeof ...(Tail) > 0 ) {
317
- return replace_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple))
319
+ return std::move (*this )
320
+ .replace_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple))
318
321
.replace (std::forward<Tail>(_tail)...);
319
322
} else {
320
- return replace_tuple (std::forward<rfl::Tuple<TupContent...>>(_tuple));
323
+ return std::move (*this ).replace_tuple (
324
+ std::forward<rfl::Tuple<TupContent...>>(_tuple));
321
325
}
322
326
}
323
327
324
328
// / Template specialization for rfl::Tuple, so we can pass fields from other
325
329
// / named tuples.
326
330
template <class ... TupContent, class ... Tail>
327
- auto replace (rfl::Tuple<TupContent...> _tuple, const Tail&... _tail) const {
331
+ auto replace (rfl::Tuple<TupContent...> _tuple, const Tail&... _tail) const & {
328
332
if constexpr (sizeof ...(Tail) > 0 ) {
329
333
return replace_tuple (std::move (_tuple)).replace (_tail...);
330
334
} else {
@@ -335,8 +339,8 @@ class NamedTuple {
335
339
// / Template specialization for NamedTuple, so we can pass fields from other
336
340
// / named tuples.
337
341
template <class ... TupContent, class ... Tail>
338
- auto replace (NamedTuple<TupContent...>&& _named_tuple, Tail&&... _tail) {
339
- return replace (
342
+ auto replace (NamedTuple<TupContent...>&& _named_tuple, Tail&&... _tail) && {
343
+ return std::move (* this ). replace (
340
344
std::forward<NamedTuple<TupContent...>>(_named_tuple).fields (),
341
345
std::forward<Tail>(_tail)...);
342
346
}
@@ -345,7 +349,7 @@ class NamedTuple {
345
349
// / named tuples.
346
350
template <class ... TupContent, class ... Tail>
347
351
auto replace (NamedTuple<TupContent...> _named_tuple,
348
- const Tail&... _tail) const {
352
+ const Tail&... _tail) const & {
349
353
return replace (_named_tuple.fields (), _tail...);
350
354
}
351
355
@@ -355,21 +359,21 @@ class NamedTuple {
355
359
// / Creates a new named tuple by applying the supplied function to every
356
360
// / field.
357
361
template <typename F>
358
- auto transform (const F& _f) {
362
+ auto transform (const F& _f) && {
359
363
const auto transform_field = [&_f](auto ... fields) {
360
364
return rfl::make_tuple (_f (std::move (fields))...);
361
365
};
362
366
const auto to_nt = []<class ... NewFields>(rfl::Tuple<NewFields...>&& _tup) {
363
367
return NamedTuple<NewFields...>(_tup);
364
368
};
365
- auto new_fields = rfl::apply (transform_field, std::move (fields () ));
369
+ auto new_fields = rfl::apply (transform_field, std::move (* this ). fields ());
366
370
return to_nt (std::move (new_fields));
367
371
}
368
372
369
373
// / Creates a new named tuple by applying the supplied function to every
370
374
// / field.
371
375
template <typename F>
372
- auto transform (const F& _f) const {
376
+ auto transform (const F& _f) const & {
373
377
const auto transform_field = [&_f](auto ... fields) {
374
378
return rfl::make_tuple (_f (std::move (fields))...);
375
379
};
@@ -480,16 +484,16 @@ class NamedTuple {
480
484
481
485
// / Replaced the field signified by the field type.
482
486
template <class Field , class T >
483
- NamedTuple<FieldTypes...> replace_value (T&& _val) {
487
+ NamedTuple<FieldTypes...> replace_value (T&& _val) && {
484
488
using FieldType = std::remove_cvref_t <Field>;
485
489
constexpr auto index = internal::find_index<FieldType::name_, Fields>();
486
- return make_replaced<index>(std::forward<Values>(values_ ),
487
- std::forward<T>(_val), seq_);
490
+ return make_replaced<index>(std::move (values_), std:: forward<T>(_val ),
491
+ seq_);
488
492
}
489
493
490
494
// / Replaced the field signified by the field type.
491
495
template <class Field , class T >
492
- NamedTuple<FieldTypes...> replace_value (T&& _val) const {
496
+ NamedTuple<FieldTypes...> replace_value (T&& _val) const & {
493
497
using FieldType = std::remove_cvref_t <Field>;
494
498
constexpr auto index = internal::find_index<FieldType::name_, Fields>();
495
499
auto values = values_;
@@ -499,17 +503,17 @@ class NamedTuple {
499
503
// / Adds the elements of a tuple to a newly created named tuple,
500
504
// / and other elements to a newly created named tuple.
501
505
template <class ... TupContent>
502
- auto replace_tuple (rfl::Tuple<TupContent...>&& _tuple) {
506
+ auto replace_tuple (rfl::Tuple<TupContent...>&& _tuple) && {
503
507
const auto r = [this ](auto &&... _fields) {
504
- return this -> replace (std::forward<TupContent>(_fields)...);
508
+ return std::move (* this ). replace (std::forward<TupContent>(_fields)...);
505
509
};
506
510
return rfl::apply (r, std::forward<rfl::Tuple<TupContent...>>(_tuple));
507
511
}
508
512
509
513
// / Adds the elements of a tuple to a newly created named tuple,
510
514
// / and other elements to a newly created named tuple.
511
515
template <class ... TupContent>
512
- auto replace_tuple (rfl::Tuple<TupContent...>&& _tuple) const {
516
+ auto replace_tuple (rfl::Tuple<TupContent...>&& _tuple) const & {
513
517
const auto r = [this ](auto &&... _fields) {
514
518
return this ->replace (std::forward<TupContent>(_fields)...);
515
519
};
0 commit comments