Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Function structure_tie

boost::pfr::structure_tie — std::tie` like function that ties fields of a structure.

Synopsis

// In header: <boost/pfr/core.hpp>


template<typename T> constexpr auto structure_tie(const T & val);
template<typename T> 
  constexpr auto 
  structure_tie(T & val, 
                std::enable_if_t< std::is_assignable< T, T >::value > * = nullptr);
template<typename T> 
  constexpr auto 
  structure_tie(T &, 
                std::enable_if_t<!std::is_assignable< T, T >::value > * = nullptr);
template<typename T> 
  constexpr auto 
  structure_tie(T &&, 
                std::enable_if_t< std::is_rvalue_reference< T && >::value > * = 0);

Description

Example:

void foo(const int&, const short&);
struct my_struct { int i, short s; };

const my_struct const_s{1, 2};
std::apply(foo, structure_tie(const_s));

my_struct s;
structure_tie(s) = std::tuple<int, short>{10, 11};
assert(s.s == 11);

Returns:

a std::tuple with lvalue and const lvalue references to fields of an simple aggregate val.


PrevUpHomeNext