# Reference Section of PFR

Includes all the Boost.PFR headers

Contains all the macros that describe Boost.PFR configuration, like BOOST_PFR_ENABLED

This header file doesn't require C++14 Standard and supports all C++ compilers, even pre C++14 compilers (C++11, C++03...).

in Visual Studio 2017 v15.9 PFR library with classic engine normally works

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
constexpr decltype(auto) std::size_t `const T &` 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`.

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;

constexpr decltype(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_assignable< T, T >::value > *nullptr`
constexpr auto std::size_t `T &&` `std::enable_if_t< std::is_rvalue_reference< T && >::value > *nullptr`
constexpr const U & `const T &`
constexpr U & `T &` `std::enable_if_t< std::is_assignable< T, T >::value > *nullptr`
constexpr U & `T &` `std::enable_if_t<!std::is_assignable< T, T >::value > *nullptr`
constexpr U && `T &&` `std::enable_if_t< std::is_rvalue_reference< T && >::value > *nullptr`
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 = boost::pfr::structure_to_tuple(s);
    assert(get<0>(t) == 10);

constexpr auto `const T &` 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, boost::pfr::structure_tie(const_s));

    my_struct s;
    boost::pfr::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`.

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 > *nullptr`
constexpr 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;
    boost::pfr::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();
    boost::pfr::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 functions boost::pfr::get_name and boost::pfr::names_as_array to know which names each field of any simple aggregate has.

See Also : 'Reflection of field names' for details.

Synopsis:

constexpr std::string_view std::size_t Returns name of a field with index `I` in simple aggregate `T`.

Example:

    struct my_struct { int i, short s; };

    assert(boost::pfr::get_name<0, my_struct>() == "i");
    assert(boost::pfr::get_name<1, my_struct>() == "s");

constexpr std::array< std::string_view, boost::pfr::tuple_size_v< T > > Creates a `std::array` from names of fields of an simple aggregate `T`.

Example:

    struct my_struct { int i, short s; };
    std::array<std::string_view, 2> a = boost::pfr::names_as_array<my_struct>();
    assert(a[0] == "i");

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)
This typedef exists only if T is void.
std::true_type
bool `const T &` `const T &`

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

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

void
std::greater like comparator that returns boost::pfr::gt (x, y)
This typedef exists only if T is void.
std::true_type
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.

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

void
std::greater_equal like comparator that returns boost::pfr::ge (x, y)
This typedef exists only if T is void.
std::true_type
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.

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

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)
This typedef exists only if T is void.
std::true_type
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.

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

void
std::less_equal like comparator that returns boost::pfr::le (x, y)
This typedef exists only if T is void.
std::true_type
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.

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

void
std::not_equal like comparator that returns boost::pfr::ne (x, y)
This typedef exists only if T is void.
std::true_type
bool `const T &` `const T &`

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

bool `const V &` `const U &`

This operator allows comparison of x and y that have different type.

Exists only if T is void.

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 manipulator to read/write simple aggregate `value` using its IO stream operators or using boost::pfr::io_fields if operators are not available.

Example:

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

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

Contains IO manipulator boost::pfr::io_fields to read/write any simple aggregate 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 manipulator 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 &` Compares lhs and rhs for equality using their own comparison and conversion operators; if no operators available 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 available 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 available 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 available 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 available 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 available returns boost::pfr::ge_fields (lhs, rhs).

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

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

std::size_t with hash of the value

unspecified `const T &`

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 traits boost::pfr::is_reflectable and boost::pfr::is_implicitly_reflectable for detecting an ability to reflect type.

Synopsis:

Has a static const member variable `value` when it is known that type T can or can't be reflected using Boost.PFR; otherwise, there is no member variable. Every user may (and in some difficult cases - should) specialize is_reflectable on his own.

Example:

    namespace boost { namespace pfr {
        template<class All> struct is_reflectable<A, All> : std::false_type {};       // 'A' won't be interpreted as reflectable everywhere
        template<> struct is_reflectable<B, boost_fusion_tag> : std::false_type {};   // 'B' won't be interpreted as reflectable in only Boost Fusion
    }}

is_reflectable affects is_implicitly_reflectable, the decision made by is_reflectable is used by is_implicitly_reflectable.

const T
WhatFor
boost::pfr::is_reflectable< T, WhatFor >
const volatile T
WhatFor
boost::pfr::is_reflectable< T, WhatFor >
volatile T
WhatFor
boost::pfr::is_reflectable< T, WhatFor >

Checks the input type for the potential to be reflected. Specialize is_reflectable if you disagree with is_implicitly_reflectable's default decision.

unspecified
constexpr bool

Checks the input type for the potential to be reflected. Specialize is_reflectable if you disagree with is_implicitly_reflectable_v's default decision.

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 satisfies simple aggregate .

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 satisfies simple aggregate .

Example:

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