| Home | Libraries | People | FAQ | More

## Function template get

boost::pfr::get — Returns reference or const reference to a field with index `I` in simple aggregate `val`. Overload taking the type `U` returns reference or const reference to a field with provided type `U` in simple aggregate `val` if there's only one field of such type in `val`.

## Synopsis

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

    template<std::size_t I, typename T>
      BOOST_PFR_BEGIN_MODULE_EXPORT constexpr decltype(auto) get(const T & val);

## 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;

    assert(boost::pfr::get<int>(s) == 10);
    boost::pfr::get<short>(s) = 11;