Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Reference Section of PFR

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

Header <boost/pfr.hpp>

Includes all the Boost.PFR headers

Contains all the macros that describe Boost.PFR configuration, like BOOST_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...).


BOOST_PFR_NOT_SUPPORTED
BOOST_PFR_USE_LOOPHOLE
BOOST_PFR_USE_CPP17
BOOST_PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE
BOOST_PFR_HAS_GUARANTEED_COPY_ELISION
BOOST_PFR_ENABLE_IMPLICIT_REFLECTION
BOOST_PFR_CORE_NAME_ENABLED
BOOST_PFR_CORE_NAME_PARSING
BOOST_PFR_MAYBE_UNUSED
BOOST_PFR_ENABLED

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

Synopsis:

namespace boost {
  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 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:

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

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:


BOOST_PFR_FUNCTIONS_FOR(T)

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:

namespace boost {
  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;
  }
}

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:

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

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:

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

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:

namespace boost {
  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 <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:

namespace boost {
  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 &);
  }
}

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

Synopsis:

namespace boost {
  namespace pfr {
    template<typename T, typename WhatFor> struct is_reflectable;

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

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

Synopsis:

namespace boost {
  namespace pfr {
    typedef unspecified tuple_size;

    constexpr std::size_t tuple_size_v;
  }
}

PrevUpHomeNext