Skip to content

Commit 77dadea

Browse files
Completed the references of NamedTuple
1 parent a9b2a91 commit 77dadea

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

include/rfl/NamedTuple.hpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,21 @@ class NamedTuple {
165165
/// Creates a new named tuple by applying the supplied function to
166166
/// field. The function is expected to return a named tuple itself.
167167
template <typename F>
168-
auto and_then(const F& _f) {
168+
auto and_then(const F& _f) && {
169169
const auto transform_field = [&_f](auto... _fields) {
170170
return rfl::tuple_cat(_f(std::move(_fields)).fields()...);
171171
};
172172
const auto to_nt = []<class... NewFields>(rfl::Tuple<NewFields...>&& _tup) {
173173
return NamedTuple<NewFields...>(_tup);
174174
};
175-
auto new_fields = rfl::apply(transform_field, std::move(fields()));
175+
auto new_fields = rfl::apply(transform_field, std::move(*this).fields());
176176
return to_nt(std::move(new_fields));
177177
}
178178

179179
/// Creates a new named tuple by applying the supplied function to
180180
/// field. The function is expected to return a named tuple itself.
181181
template <typename F>
182-
auto and_then(const F& _f) const {
182+
auto and_then(const F& _f) const& {
183183
const auto transform_field = [&_f](auto... _fields) {
184184
return rfl::tuple_cat(_f(std::move(_fields)).fields()...);
185185
};
@@ -283,13 +283,15 @@ class NamedTuple {
283283
/// Replaces one or several fields, returning a new version
284284
/// with the non-replaced fields left unchanged.
285285
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) && {
287288
using RField = Field<_name, FType>;
288289
constexpr auto num_other_fields = sizeof...(OtherRFields);
289290
if constexpr (num_other_fields == 0) {
290-
return replace_value<RField>(_field.value_);
291+
return std::move(*this).template replace_value<RField>(_field.value_);
291292
} else {
292-
return replace_value<RField>(_field.value_)
293+
return std::move(*this)
294+
.template replace_value<RField>(_field.value_)
293295
.replace(std::forward<OtherRFields>(_other_fields)...);
294296
}
295297
}
@@ -298,7 +300,7 @@ class NamedTuple {
298300
/// with the non-replaced fields left unchanged.
299301
template <internal::StringLiteral _name, class FType, class... OtherRFields>
300302
auto replace(Field<_name, FType> _field,
301-
const OtherRFields&... _other_fields) const {
303+
const OtherRFields&... _other_fields) const& {
302304
using RField = Field<_name, FType>;
303305
constexpr auto num_other_fields = sizeof...(OtherRFields);
304306
if constexpr (num_other_fields == 0) {
@@ -312,19 +314,21 @@ class NamedTuple {
312314
/// Template specialization for rfl::Tuple, so we can pass fields from other
313315
/// named tuples.
314316
template <class... TupContent, class... Tail>
315-
auto replace(rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) {
317+
auto replace(rfl::Tuple<TupContent...>&& _tuple, Tail&&... _tail) && {
316318
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))
318321
.replace(std::forward<Tail>(_tail)...);
319322
} 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));
321325
}
322326
}
323327

324328
/// Template specialization for rfl::Tuple, so we can pass fields from other
325329
/// named tuples.
326330
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& {
328332
if constexpr (sizeof...(Tail) > 0) {
329333
return replace_tuple(std::move(_tuple)).replace(_tail...);
330334
} else {
@@ -335,8 +339,8 @@ class NamedTuple {
335339
/// Template specialization for NamedTuple, so we can pass fields from other
336340
/// named tuples.
337341
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(
340344
std::forward<NamedTuple<TupContent...>>(_named_tuple).fields(),
341345
std::forward<Tail>(_tail)...);
342346
}
@@ -345,7 +349,7 @@ class NamedTuple {
345349
/// named tuples.
346350
template <class... TupContent, class... Tail>
347351
auto replace(NamedTuple<TupContent...> _named_tuple,
348-
const Tail&... _tail) const {
352+
const Tail&... _tail) const& {
349353
return replace(_named_tuple.fields(), _tail...);
350354
}
351355

@@ -355,21 +359,21 @@ class NamedTuple {
355359
/// Creates a new named tuple by applying the supplied function to every
356360
/// field.
357361
template <typename F>
358-
auto transform(const F& _f) {
362+
auto transform(const F& _f) && {
359363
const auto transform_field = [&_f](auto... fields) {
360364
return rfl::make_tuple(_f(std::move(fields))...);
361365
};
362366
const auto to_nt = []<class... NewFields>(rfl::Tuple<NewFields...>&& _tup) {
363367
return NamedTuple<NewFields...>(_tup);
364368
};
365-
auto new_fields = rfl::apply(transform_field, std::move(fields()));
369+
auto new_fields = rfl::apply(transform_field, std::move(*this).fields());
366370
return to_nt(std::move(new_fields));
367371
}
368372

369373
/// Creates a new named tuple by applying the supplied function to every
370374
/// field.
371375
template <typename F>
372-
auto transform(const F& _f) const {
376+
auto transform(const F& _f) const& {
373377
const auto transform_field = [&_f](auto... fields) {
374378
return rfl::make_tuple(_f(std::move(fields))...);
375379
};
@@ -480,16 +484,16 @@ class NamedTuple {
480484

481485
/// Replaced the field signified by the field type.
482486
template <class Field, class T>
483-
NamedTuple<FieldTypes...> replace_value(T&& _val) {
487+
NamedTuple<FieldTypes...> replace_value(T&& _val) && {
484488
using FieldType = std::remove_cvref_t<Field>;
485489
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_);
488492
}
489493

490494
/// Replaced the field signified by the field type.
491495
template <class Field, class T>
492-
NamedTuple<FieldTypes...> replace_value(T&& _val) const {
496+
NamedTuple<FieldTypes...> replace_value(T&& _val) const& {
493497
using FieldType = std::remove_cvref_t<Field>;
494498
constexpr auto index = internal::find_index<FieldType::name_, Fields>();
495499
auto values = values_;
@@ -499,17 +503,17 @@ class NamedTuple {
499503
/// Adds the elements of a tuple to a newly created named tuple,
500504
/// and other elements to a newly created named tuple.
501505
template <class... TupContent>
502-
auto replace_tuple(rfl::Tuple<TupContent...>&& _tuple) {
506+
auto replace_tuple(rfl::Tuple<TupContent...>&& _tuple) && {
503507
const auto r = [this](auto&&... _fields) {
504-
return this->replace(std::forward<TupContent>(_fields)...);
508+
return std::move(*this).replace(std::forward<TupContent>(_fields)...);
505509
};
506510
return rfl::apply(r, std::forward<rfl::Tuple<TupContent...>>(_tuple));
507511
}
508512

509513
/// Adds the elements of a tuple to a newly created named tuple,
510514
/// and other elements to a newly created named tuple.
511515
template <class... TupContent>
512-
auto replace_tuple(rfl::Tuple<TupContent...>&& _tuple) const {
516+
auto replace_tuple(rfl::Tuple<TupContent...>&& _tuple) const& {
513517
const auto r = [this](auto&&... _fields) {
514518
return this->replace(std::forward<TupContent>(_fields)...);
515519
};

0 commit comments

Comments
 (0)