kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches

◆ forward_as_record()

template<str... Fields, typename... Ts>
constexpr auto forward_as_record ( Ts &&...  ts) -> record<field_capture<Fields, Ts&&>...>
related

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

Constructs a record of references to the arguments in args 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.
Template Parameters
FieldsNon type template parameters names to associate to the each element.
Parameters
tsZero or more lvalue arguments to construct the record from.
Returns
A kumi::record constructed as kumi::record<Ts&&...>(std::forward<Ts>(args)...)

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"_f>(d)
, std::move(kumi::get<"b"_f>(d))
);
}
int main()
{
auto v = build( kumi::forward_as_record<"a"_f, "b"_f>(4,std::string{"the text !"}));
for(auto const& s : v)
std::cout << s << "\n";
}