Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Reference Section of PFR

Header <pfr.hpp>
Header <pfr/config.hpp>
Header <pfr/core.hpp>
Header <pfr/core_name.hpp>
Header <pfr/functions_for.hpp>
Header <pfr/functors.hpp>
Header <pfr/io.hpp>
Header <pfr/io_fields.hpp>
Header <pfr/ops.hpp>
Header <pfr/ops_fields.hpp>
Header <pfr/traits.hpp>
Header <pfr/traits_fwd.hpp>
Header <pfr/tuple_size.hpp>

Header <pfr.hpp>

Includes all the Boost.PFR headers

Header <pfr/config.hpp>

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

[Note] Note

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


PFR_NOT_SUPPORTED
PFR_USE_LOOPHOLE
PFR_USE_CPP17
PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE
PFR_HAS_GUARANTEED_COPY_ELISION
PFR_ENABLE_IMPLICIT_REFLECTION
PFR_CORE_NAME_ENABLED
PFR_CORE_NAME_PARSING
PFR_MAYBE_UNUSED
PFR_ENABLED

Header <pfr/core.hpp>

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

Synopsis:

namespace pfr {
  typedef unspecified tuple_element;
  typedef typename tuple_element< I, T >::type tuple_element_t;
  template<std::size_t I, typename T> constexpr decltype(auto) get(const T &);
  template<std::size_t I, typename T> 
    constexpr decltype(auto) 
    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 > * = nullptr);
  template<typename U, typename T> constexpr const U & get(const T & val);
  template<typename U, typename T> 
    constexpr U & 
    get(T & val, 
        std::enable_if_t< std::is_assignable< T, T >::value > * = nullptr);
  template<typename U, typename T> 
    constexpr U & 
    get(T &, 
        std::enable_if_t<!std::is_assignable< T, T >::value > * = nullptr);
  template<typename U, typename T> 
    constexpr U && 
    get(T && val, 
        std::enable_if_t< std::is_rvalue_reference< T && >::value > * = nullptr);
  template<typename T> constexpr auto structure_to_tuple(const T &);
  template<typename T> constexpr auto structure_tie(const T &);
  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 > * = nullptr);
  template<typename T, typename F> constexpr void for_each_field(T &&, F &&);
  template<typename... Elements> unspecified tie_from_structure(Elements &...);
}

Contains functions pfr::get_name and pfr::names_as_array to know which names each field of any simple aggregate has.

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

Synopsis:

namespace pfr {
  template<std::size_t I, typename T> constexpr std::string_view get_name();
  template<typename T> 
    constexpr std::array< std::string_view, pfr::tuple_size_v< T > > 
    names_as_array();
}

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

#include <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;
    };
    PFR_FUNCTIONS_FOR(my_struct)
}

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

Synopsis:


PFR_FUNCTIONS_FOR(T)

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

Example:

#include <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,
    pfr::hash<>,
    pfr::equal_to<>
> my_set;

Synopsis:

namespace pfr {
  template<typename T = void> struct equal_to;
  template<typename T = void> struct greater;
  template<typename T = void> struct greater_equal;
  template<typename T> struct hash;
  template<typename T = void> struct less;
  template<typename T = void> struct less_equal;
  template<typename T = void> struct not_equal;
}

Header <pfr/io.hpp>

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

Example:

#include <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 << 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:

namespace pfr {
  template<typename T> auto io(T &&);
}

Contains IO manipulator 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 << pfr::io_fields(x);  // Equivalent to: os << "{ " << x.i << " ," <<  x.s << " }"
}

std::istream& operator>>(std::istream& is, my_struct& x) {
    return is >> 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:

namespace pfr {
  template<typename T> auto io_fields(T &&);
}

Header <pfr/ops.hpp>

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 pfr/ops.hpp header.

Example:

#include <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(pfr::lt(s1, s2));

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

Synopsis:

namespace pfr {
  template<typename T, typename U> unspecified eq(const T &, const U &);
  template<typename T, typename U> 
    unspecified eq(const T & lhs, const U & rhs);
  template<typename T, typename U> unspecified ne(const T &, const U &);
  template<typename T, typename U> 
    unspecified ne(const T & lhs, const U & rhs);
  template<typename T, typename U> unspecified lt(const T &, const U &);
  template<typename T, typename U> 
    unspecified lt(const T & lhs, const U & rhs);
  template<typename T, typename U> unspecified gt(const T &, const U &);
  template<typename T, typename U> 
    unspecified gt(const T & lhs, const U & rhs);
  template<typename T, typename U> unspecified le(const T &, const U &);
  template<typename T, typename U> 
    unspecified le(const T & lhs, const U & rhs);
  template<typename T, typename U> unspecified ge(const T &, const U &);
  template<typename T, typename U> 
    unspecified ge(const T & lhs, const U & rhs);
  template<typename T> unspecified hash_value(const T &);
  template<typename T> unspecified hash_value(const T & value);
}

Contains field-by-fields comparison and hash functions.

Example:

#include <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(pfr::lt_fields(s1, s2));

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

Synopsis:

namespace pfr {
  template<typename T, typename U> 
    constexpr bool eq_fields(const T &, const U &);
  template<typename T, typename U> 
    constexpr bool ne_fields(const T &, const U &);
  template<typename T, typename U> 
    constexpr bool gt_fields(const T &, const U &);
  template<typename T, typename U> 
    constexpr bool lt_fields(const T &, const U &);
  template<typename T, typename U> 
    constexpr bool ge_fields(const T &, const U &);
  template<typename T, typename U> 
    constexpr bool le_fields(const T &, const U &);
  template<typename T> std::size_t hash_fields(const T &);
}

Header <pfr/traits.hpp>

Contains traits pfr::is_reflectable and pfr::is_implicitly_reflectable for detecting an ability to reflect type.

Synopsis:

namespace pfr {
  template<typename T, typename WhatFor> 
    struct is_reflectable<const T, WhatFor>;
  template<typename T, typename WhatFor> 
    struct is_reflectable<const volatile T, WhatFor>;
  template<typename T, typename WhatFor> 
    struct is_reflectable<volatile T, WhatFor>;
  typedef unspecified is_implicitly_reflectable;

  constexpr bool is_implicitly_reflectable_v;
}
namespace pfr {
  template<typename T, typename WhatFor> struct is_reflectable;
}

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

Synopsis:

namespace pfr {
  typedef unspecified tuple_size;

  constexpr std::size_t tuple_size_v;
}

PrevUpHomeNext