Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

Reference Section

Header <boost/pfr.hpp>
Header <boost/pfr/core.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/tuple_size.hpp>

Header <boost/pfr.hpp>

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:

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> 
      decltype(auto) constexpr get(const T &);
    template<std::size_t I, typename T> 
      decltype(auto) constexpr 
      get(T &, 
          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 &&, 
          std::enable_if_t< std::is_rvalue_reference< T && >::value > * = 0);
    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 &, 
                    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 > * = 0);
    template<typename T, typename F> void for_each_field(T &&, F &&);
    template<typename... Elements> 
      unspecified tie_from_structure(Elements &...);
  }
}

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

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 &, const U &);
    template<typename T, typename U> unspecified ne(const T &, const U &);
    template<typename T, typename U> unspecified ne(const T &, const U &);
    template<typename T, typename U> unspecified lt(const T &, const U &);
    template<typename T, typename U> unspecified lt(const T &, const U &);
    template<typename T, typename U> unspecified gt(const T &, const U &);
    template<typename T, typename U> unspecified gt(const T &, const U &);
    template<typename T, typename U> unspecified le(const T &, const U &);
    template<typename T, typename U> unspecified le(const T &, const U &);
    template<typename T, typename U> unspecified ge(const T &, const U &);
    template<typename T, typename U> unspecified ge(const T &, const U &);
    template<typename T> unspecified hash_value(const T &);
    template<typename T> unspecified hash_value(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:

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