Home | Libraries | People | FAQ | More |
Caution | |
---|---|
Recommended C++ Standards are C++20 and above. C++17 completely enough for a user who doesn't want accessing name of structure member. Library requires at least C++14! Pre C++14 compilers (C++11, C++03...) are not supported. |
PFR library works with types that satisfy the requirements of SimpleAggregate
: aggregate types without
base classes, const
fields, references,
or C arrays:
struct simple_aggregate { // SimpleAggregate std::string name; int age; boost::uuids::uuid uuid; }; struct empty { // SimpleAggregate }; struct aggregate : empty { // not a SimpleAggregate std::string name; int age; boost::uuids::uuid uuid; };
The library may work with aggregates that don't satisfy the requirements of
SimpleAggregate
, but the behavior
tends to be non-portable.
PFRs extraction of field name works with a SimpleAggregate
with non-internal linkage (with aggregats that could be used as extern T t;
). Do not
use this functionality with anonymous structures, local structures or a structure
defined inside anonymous namespace as the behavior tends to be non-portable.
By default PFR auto-detects your compiler abilities and automatically defines the configuration macro into appropriate values. If you wish to override that behavior, just define:
Table 1.2. Macros
Macro name |
Effect |
---|---|
PFR_USE_CPP17 |
Define to |
PFR_USE_LOOPHOLE |
Define to |
PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE |
Define to |
PFR_HAS_GUARANTEED_COPY_ELISION |
Define to |
PFR_ENABLE_IMPLICIT_REFLECTION |
Define to |
PFR_CORE_NAME_ENABLED |
On platforms where field name extraction is not supported, the 'pfr/config.hpp' header defines the PFR_CORE_NAME_ENABLED macro equal to 0. Defining this macro as 0 before including the header disables the ability to get a field name. |
PFR_FUNCTION_SIGNATURE |
For known compilers defined to a compiler specific macro, that outputs the whole function signature including non-type template parameters. |
PFR_CORE_NAME_PARSING |
Describes extraction of field name from PFR_FUNCTION_SIGNATURE macro. See details below. |
PFR_ENABLED |
On platforms where PFR is not supported, the |
The PFRs reflection has some limitations that depend on a C++ Standard and compiler capabilities:
pfr::get
, pfr::structure_to_tuple
,
pfr::structure_tie
,
pfr/core.hpp
require T to be a POD type with built-in types only.
The PFRs extraction of field name has some limitations that depend on a C++ Standard and compiler capabilities:
extern T t;
, i.e. has a non-internal linkage.
PFR_CORE_NAME_PARSING
is already
set up for most of the popular compilers. You need to adjust it only if some
static_assert in the library complained on PFR_CORE_NAME_PARSING
.
To do that:
test/core_name/print_name.cpp
with your compiler and run it
(skip_at_begin,
skip_at_end,
"")
,
where
skip_at_begin
is
equal to characters count before the first occurrence of user_defined_field
in output
skip_at_end
is equal
to characters count after last occurrence of user_defined_field
in output
test/core_name/print_name.cpp
returns "user_defined_field"
user_defined_field
,
then define PFR_CORE_NAME_PARSING to (skip_at_begin,
skip_at_end,
"T = ")
,
where
skip_at_begin
is
equal to skip_at_begin
at step 2
skip_at_end
is equal
to skip_at_end
at
step 2
"T = "
is equal
to characters that are right before the user_defined_field
in output, use backward("T = ")
to search for the occurange in the
string from the right
PFR_CORE_NAME_PARSING
macro and the initial output of test/core_name/print_name.cpp
.