KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

◆ forward_as_record

template<kumi::concepts::identifier auto... Fields>
forward_as_record_t<Fields...> kumi::forward_as_record {}
inlineconstexprnodiscard

Creates a kumi::record of forwarding references to its arguments.

Constructs a record of references to the arguments in ts suitable for forwarding as an argument to a function. The record has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members.

Note
If the arguments are temporaries, forward_as_record does not extend their lifetime; they have to be used before the end of the full expression.

Header file

#include <kumi/product_types/record.hpp>

Call Signature

template<typename... Ts>
constexpr auto forward_as_record(Ts&&... ts);

Parameters

  • Fields: Non type template parameters names to associate with each element.
  • ts: Zero or more lvalue arguments to construct the record from.

Return value

Example

#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
#include <string>
using namespace kumi::literals;
template<typename Data>
std::vector<std::string> build(Data d)
{
return std::vector<std::string> ( kumi::get<"a"_id>(d)
, std::move(kumi::get<"b"_id>(d))
);
}
int main()
{
auto v = build( kumi::forward_as_record<"a"_id, "b"_id>(4,std::string{"the text !"}));
for(auto const& s : v)
std::cout << s << "\n";
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:766