...one of the most highly regarded and expertly designed C++ library projects in the world.
— Herb Sutter and Andrei Alexandrescu, C++ Coding Standards
包含所有 Boost.PFR 头文件
包含所有描述 Boost.PFR 配置的宏,例如 BOOST_PFR_ENABLED
![]() |
注意 |
---|---|
此头文件不需要 C++14 标准,支持所有 C++ 编译器,甚至 C++14 之前的编译器(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 BOOST_PFR_BEGIN_MODULE_EXPORT BOOST_PFR_END_MODULE_EXPORT
包含所有基本的类元组接口 boost::pfr::get 、 boost::pfr::tuple_size 、 boost::pfr::tuple_element_t 等。
提要
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> BOOST_PFR_BEGIN_MODULE_EXPORT constexpr decltype(auto) get(const T &); template<std::size_t I, typename T> decltype(auto) get(T & val, std::enable_if_t< std::is_assignable< T, T >::value > * = nullptr); template<std::size_t I, typename T> auto get(T &, std::enable_if_t<!std::is_assignable< T, T >::value > * = nullptr); template<std::size_t I, typename T> auto get(T && val, std::enable_if_t< std::is_rvalue_reference< T && >::value > * = nullptr); template<typename U, typename T> const U & get(const T & val); template<typename U, typename T> U & get(T & val, std::enable_if_t< std::is_assignable< T, T >::value > * = nullptr); template<typename U, typename T> U & get(T &, std::enable_if_t<!std::is_assignable< T, T >::value > * = nullptr); template<typename U, typename T> U && get(T && val, std::enable_if_t< std::is_rvalue_reference< T && >::value > * = nullptr); template<typename T> auto structure_to_tuple(const T &); template<typename... Elements> unspecified tie_from_structure(Elements &... args); } }
包含函数 boost::pfr::get_name 和 boost::pfr::names_as_array ,用于了解任何 简单聚合体 的字段名称。
另见 : '字段名称反射' 了解详情。
提要
namespace boost { namespace pfr { template<std::size_t I, typename T> BOOST_PFR_BEGIN_MODULE_EXPORT constexpr std::string_view get_name(); template<typename T> std::array< std::string_view, boost::pfr::tuple_size_v< T > > names_as_array(); template<typename T, typename F> void for_each_field_with_name(T &&, F &&); } }
包含 BOOST_PFR_FUNCTIONS_FOR 宏,该宏为 T 定义了比较和流运算符以及 hash_value 函数。 示例:
#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) }
另见 : '获取运算符的三种方式' 了解定义运算符的其他方法和更多详情。
提要
BOOST_PFR_FUNCTIONS_FOR(T)
包含与标准库函数对象相似的函数对象。每个函数对象调用 boost/pfr/ops.hpp 中的相应 Boost.PFR 函数。
示例
#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;
提要
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; } }
包含类型 boost::pfr::io 的 IO 流操作符。如果类型可以通过其自身的运算符或转换运算符进行流操作,则将使用该类型的运算符。
示例
#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}
另见 : '获取运算符的三种方式' 了解定义运算符的其他方法和更多详情。
提要
namespace boost { namespace pfr { template<typename T> BOOST_PFR_BEGIN_MODULE_EXPORT auto io(T &&); } }
包含 IO 操作符 boost::pfr::io_fields ,用于逐个字段读写任何 简单聚合体。
示例
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 >> " }" }
另见 : '获取运算符的三种方式' 了解定义运算符的其他方法和更多详情。
提要
namespace boost { namespace pfr { template<typename T> BOOST_PFR_BEGIN_MODULE_EXPORT auto io_fields(T &&); } }
包含比较和哈希函数。如果类型可以通过其自身的运算符或转换运算符进行比较,则将使用该类型的运算符。否则,操作将通过 boost/pfr/ops.hpp 头文件中的相应函数进行。
示例
#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));
另见 : '获取运算符的三种方式' 了解定义运算符的其他方法和更多详情。
提要
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); } }
包含逐字段比较和哈希函数。
示例
#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));
另见 : '获取运算符的三种方式' 了解定义运算符的其他方法和更多详情。
提要
namespace boost { namespace pfr { template<typename T, typename U> BOOST_PFR_BEGIN_MODULE_EXPORT constexpr bool eq_fields(const T &, const U &); template<typename T, typename U> bool ne_fields(const T &, const U &); template<typename T, typename U> bool gt_fields(const T &, const U &); template<typename T, typename U> bool lt_fields(const T &, const U &); template<typename T, typename U> bool ge_fields(const T &, const U &); template<typename T, typename U> bool le_fields(const T &, const U &); template<typename T> std::size_t hash_fields(const T &); } }
包含特性 boost::pfr::is_reflectable 和 boost::pfr::is_implicitly_reflectable ,用于检测类型是否可反射。
提要
namespace boost { 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; bool is_implicitly_reflectable_v; } }
namespace boost { namespace pfr { template<typename T, typename WhatFor> struct is_reflectable; } }
包含元组类接口,用于获取字段计数 boost::pfr::tuple_size 、 boost::pfr::tuple_size_v 。
提要
namespace boost { namespace pfr { typedef unspecified tuple_size; std::size_t tuple_size_v; } }