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 get

boost::pfr::get — Returns reference or const reference to a field with index I in simple aggregate val.

Synopsis

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


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

Description

Example:

struct my_struct { int i, short s; };
my_struct s {10, 11};
assert(boost::pfr::get<0>(s) == 10);
boost::pfr::get<1>(s) = 0;


PrevUpHomeNext