#ifndef RFL_REPLACE_HPP_ #define RFL_REPLACE_HPP_ #include #include "from_named_tuple.hpp" namespace rfl { /// Replaces one or several fields, returning a new version /// with the non-replaced fields left unchanged. template auto replace(T&& _t, RField&& _field, OtherRFields&&... _other_fields) { if constexpr (internal::is_named_tuple_v) { return std::forward(_t).replace( to_named_tuple(std::forward(_field)), to_named_tuple(std::forward(_other_fields))... ); } else { return from_named_tuple( to_named_tuple(std::forward(_t)) .replace( to_named_tuple(std::forward(_field)), to_named_tuple(std::forward(_other_fields))... ) ); } } /// Replaces one or several fields, returning a new version /// with the non-replaced fields left unchanged. template auto replace(const T& _t, RField&& _field, OtherRFields&&... _other_fields) { if constexpr (internal::is_named_tuple_v) { return _t.replace( to_named_tuple(std::forward(_field)), to_named_tuple(std::forward(_other_fields))... ); } else { return from_named_tuple(to_named_tuple(_t).replace( to_named_tuple(std::forward(_field)), to_named_tuple(std::forward(_other_fields))... )); } } } // namespace rfl #endif