# Reference Section

Includes all the Boost.PFR headers

Contains all the basic tuple-like interfaces boost::pfr::get , boost::pfr::tuple_size , boost::pfr::tuple_element_t , and others.

Synopsis:

tuple_element
has a member typedef `type` that returns the type of a field with index I in simple aggregate T.

Example:

    std::vector< boost::pfr::tuple_element<0, my_structure>::type > v;

unspecified
Type of a field with index `I` in simple aggregate `T`.

Example:

    std::vector< boost::pfr::tuple_element_t<0, my_structure> > v;

typename tuple_element< I, T >::type
decltype(auto) constexpr std::size_t `const T &`
decltype(auto) constexpr std::size_t `T &` `std::enable_if_t< std::is_assignable< T, T >::value > *nullptr`
constexpr auto std::size_t `T &` `std::enable_if_t<!std::is_assignable< T, T >::value > *nullptr`
constexpr auto std::size_t `T &&` `std::enable_if_t< std::is_rvalue_reference< T && >::value > *0`
Returns reference or const reference to a field with index `I` in simple aggregate `val`.

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;

constexpr auto `const T &` Creates a `std::tuple` from fields of an simple aggregate `val`.

Example:

    struct my_struct { int i, short s; };
    my_struct s {10, 11};
    std::tuple<int, short> t = make_tuple(s);
    assert(get<0>(t) == 10);

constexpr auto `const T &`
constexpr auto `T &` `std::enable_if_t< std::is_assignable< T, T >::value > *nullptr`
constexpr auto `T &` `std::enable_if_t<!std::is_assignable< T, T >::value > *nullptr`
constexpr auto `T &&` `std::enable_if_t< std::is_rvalue_reference< T && >::value > *0`
std::tie` like function that ties fields of a structure.

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

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

void `T &&

To each field of this variable will be the `func` applied.

` `F &&

must have one of the following signatures:

- any_return_type func(U&& field) // field of value is perfect forwarded to function

- any_return_type func(U&& field, std::size_t i)

- any_return_type func(U&& value, I i) // Here I is an `std::integral_constant<size_t, field_index>`

`

Calls `func` for each field of a `value`.

Example:

    struct my_struct { int i, short s; };
    int sum = 0;
    for_each_field(my_struct{20, 22}, [&sum](const auto& field) { sum += field; });
    assert(sum == 42);

unspecified typename... `Elements &...` std::tie-like function that allows assigning to tied values from aggregates.

Example:

    auto f() {
      struct { struct { int x, y } p; short s; } res { { 4, 5 }, 6 };
      return res;
    }
    auto [p, s] = f();
    tie_from_structure(p, s) = f();

an object with lvalue references to `args...`; on assignment of an simple aggregate value to that object each field of an aggregate is assigned to the corresponding `args...` reference.

Contains BOOST_PFR_FUNCTIONS_FOR macro that defined comparison and stream operators for T along with hash_value function. Example:

    #include <boost/pfr/functions_for.hpp>

    namespace my_namespace {
        struct my_struct {      // No operators defined for that structure
            int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
        };
        BOOST_PFR_FUNCTIONS_FOR(my_struct)
    }

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Synopsis:

Defines comparison and stream operators for T along with hash_value function.

Example:

    #include <boost/pfr/functions_for.hpp>
    struct comparable_struct {      // No operators defined for that structure
        int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
    };
    BOOST_PFR_FUNCTIONS_FOR(comparable_struct)
    // ...

    comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11};
    comparable_struct s2 {0, 1, "Hello", false, 6,7,8,9,10,11111};
    assert(s1 < s2);
    std::cout << s1 << std::endl; // Outputs: {0, 1, H, e, l, l, o, , , 0, 6, 7, 8, 9, 10, 11}

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Defines following for T:

    bool operator==(const T& lhs, const T& rhs);
    bool operator!=(const T& lhs, const T& rhs);
    bool operator< (const T& lhs, const T& rhs);
    bool operator> (const T& lhs, const T& rhs);
    bool operator<=(const T& lhs, const T& rhs);
    bool operator>=(const T& lhs, const T& rhs);

    template <class Char, class Traits>
    std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& out, const T& value);

    template <class Char, class Traits>
    std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& in, T& value);

    // helper function for Boost unordered containers and boost::hash<>.
    std::size_t hash_value(const T& value);

Contains functors that are close to the Standard Library ones. Each functor calls corresponding Boost.PFR function from boost/pfr/ops.hpp

Example:

    #include <boost/pfr/functors.hpp>
    struct my_struct {      // No operators defined for that structure
        int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
    };
    // ...

    std::unordered_set<
        my_struct,
        boost::pfr::hash<>,
        boost::pfr::equal_to<>
    > my_set;

Synopsis:

void
std::equal_to like comparator that returns boost::pfr::eq (x, y)
bool `const T &` `const T &`

true if each field of x equals the field with same index of y.

void
std::greater like comparator that returns boost::pfr::gt (x, y)
bool `const T &` `const T &`

true if field of x greater than the field with same index of y and all previous fields of x equal to the same fields of y.

void
std::greater_equal like comparator that returns boost::pfr::ge (x, y)
bool `const T &` `const T &`

true if field of x greater than the field with same index of y and all previous fields of x equal to the same fields of y; or if each field of x equals the field with same index of y.

std::hash like functor that returns boost::pfr::hash_value (x)
std::size_t `const T &`

hash value of x.

void
std::less like comparator that returns boost::pfr::lt (x, y)
bool `const T &` `const T &`

true if field of x less than the field with same index of y and all previous fields of x equal to the same fields of y.

void
std::less_equal like comparator that returns boost::pfr::le (x, y)
bool `const T &` `const T &`

true if field of x less than the field with same index of y and all previous fields of x equal to the same fields of y; or if each field of x equals the field with same index of y.

void
std::not_equal like comparator that returns boost::pfr::ne (x, y)
bool `const T &` `const T &`

true if at least one field x not equals the field with same index of y.

Contains IO stream manipulator boost::pfr::io for types. If type is streamable using its own operator or its conversion operator, then the types operator is used.

Example:

    #include <boost/pfr/io.hpp>
    struct comparable_struct {      // No operators defined for that structure
        int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
    };
    // ...

    comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11};
    std::cout << boost::pfr::io(s1);  // Outputs: {0, 1, H, e, l, l, o, , , 0, 6, 7, 8, 9, 10, 11}

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Synopsis:

auto `T &&`

IO manupulator to read/write simple aggregate `value` using its IO stream operators or using boost::pfr::io_fields if operators are not awailable.

Example:

    struct my_struct { int i; short s; };
    my_struct s;
    std::stringstream ss;
    ss << "{ 12, 13 }";
    ss >> boost::pfr::io(s);
    assert(s.i == 12);
    assert(s.i == 13);

See Also : 'Custom printing of aggregates' for info on how to implement your own manipulator with custom format.

Contains IO manupulator boost::pfr::io_fields to read/write simple aggregate `value` field-by-field.

Example:

    struct my_struct {
        int i;
        short s;
    };

    std::ostream& operator<<(std::ostream& os, const my_struct& x) {
        return os << boost::pfr::io_fields(x);  // Equivalent to: os << "{ " << x.i << " ," <<  x.s << " }"
    }

    std::istream& operator>>(std::istream& is, my_struct& x) {
        return is >> boost::pfr::io_fields(x);  // Equivalent to: is >> "{ " >> x.i >> " ," >>  x.s >> " }"
    }

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Synopsis:

auto `T &&`

IO manupulator to read/write simple aggregate `value` field-by-field.

Example:

    struct my_struct {
        int i;
        short s;
    };

    std::ostream& operator<<(std::ostream& os, const my_struct& x) {
        return os << boost::pfr::io_fields(x);  // Equivalent to: os << "{ " << x.i << " ," <<  x.s << " }"
    }

    std::istream& operator>>(std::istream& is, my_struct& x) {
        return is >> boost::pfr::io_fields(x);  // Equivalent to: is >> "{ " >> x.i >> " ," >>  x.s >> " }"
    }

Input and output streaming operators for `boost::pfr::io_fields` are symmetric, meaning that you get the original value by streaming it and reading back if each fields streaming operator is symmetric.

See Also : 'Custom printing of aggregates' for info on how to implement your own manipulator with custom format.

Contains comparison and hashing functions. If type is comparable using its own operator or its conversion operator, then the types operator is used. Otherwise the operation is done via corresponding function from boost/pfr/ops.hpp header.

Example:

    #include <boost/pfr/ops.hpp>
    struct comparable_struct {      // No operators defined for that structure
        int i; short s; char data[7]; bool bl; int a,b,c,d,e,f;
    };
    // ...

    comparable_struct s1 {0, 1, "Hello", false, 6,7,8,9,10,11};
    comparable_struct s2 {0, 1, "Hello", false, 6,7,8,9,10,11111};
    assert(boost::pfr::lt(s1, s2));

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Synopsis:

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for equality using their own comparison and conversion operators; if no operators avalable returns boost::pfr::eq_fields (lhs, rhs).

true if lhs is equal to rhs; false otherwise

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for inequality using their own comparison and conversion operators; if no operators avalable returns boost::pfr::ne_fields (lhs, rhs).

true if lhs is not equal to rhs; false otherwise

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for less-than using their own comparison and conversion operators; if no operators avalable returns boost::pfr::lt_fields (lhs, rhs).

true if lhs is less than rhs; false otherwise

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for greater-than using their own comparison and conversion operators; if no operators avalable returns boost::pfr::lt_fields (lhs, rhs).

true if lhs is greater than rhs; false otherwise

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for less-equal using their own comparison and conversion operators; if no operators avalable returns boost::pfr::le_fields (lhs, rhs).

true if lhs is less or equal to rhs; false otherwise

unspecified `const T &` `const U &`
unspecified `const T &` `const U &`
Compares lhs and rhs for greater-equal using their own comparison and conversion operators; if no operators avalable returns boost::pfr::ge_fields (lhs, rhs).

true if lhs is greater or equal to rhs; false otherwise

unspecified `const T &`
unspecified `const T &`
Hashes value using its own std::hash specialization; if no std::hash specialization avalable returns boost::pfr::hash_fields (value).

std::size_t with hash of the value

Contains field-by-fields comparison and hash functions.

Example:

    #include <boost/pfr/ops_fields.hpp>
    struct comparable_struct {      // No operators defined for that structure
        int i; short s;
    };
    // ...

    comparable_struct s1 {0, 1};
    comparable_struct s2 {0, 2};
    assert(boost::pfr::lt_fields(s1, s2));

See Also : 'Three ways of getting operators' for other ways to define operators and more details.

Synopsis:

constexpr bool `const T &` `const U &`

Does a field-by-field equality comparison.

`L == R && tuple_size_v<T> == tuple_size_v<U>`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

constexpr bool `const T &` `const U &`

Does a field-by-field inequality comparison.

`L != R || tuple_size_v<T> != tuple_size_v<U>`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

constexpr bool `const T &` `const U &`

Does a field-by-field greter comparison.

`L > R || (L == R && tuple_size_v<T> > tuple_size_v<U>)`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

constexpr bool `const T &` `const U &`

Does a field-by-field less comparison.

`L < R || (L == R && tuple_size_v<T> < tuple_size_v<U>)`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

constexpr bool `const T &` `const U &`

Does a field-by-field greater equal comparison.

`L > R || (L == R && tuple_size_v<T> >= tuple_size_v<U>)`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

constexpr bool `const T &` `const U &`

Does a field-by-field less equal comparison.

`L < R || (L == R && tuple_size_v<T> <= tuple_size_v<U>)`, where `L` and `R` are the results of calling `std::tie` on first `N` fields of `lhs` and

std::size_t `const T &`

Does a field-by-field hashing.

combined hash of all the fields

Contains tuple-like interfaces to get fields count boost::pfr::tuple_size , boost::pfr::tuple_size_v .

Synopsis:

Has a static const member variable `value` that contains fields count in a T. Works for any T that supports aggregate initialization.

Example:

    std::array<int, boost::pfr::tuple_size<my_structure>::value > a;

unspecified
constexpr std::size_t

`tuple_size_v` is a template variable that contains fields count in a T and works for any T that supports aggregate initialization.

Example:

    std::array<int, boost::pfr::tuple_size_v<my_structure> > a;