Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Limitations and Configuration

[Caution] 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.

Configuration Macro

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 1 if you wish to override PFR choice and use C++17 structured bindings for reflection. Define to 0 to override PFR choice and disable C++17 structured bindings usage.

PFR_USE_LOOPHOLE

Define to 1 if you wish to override PFR choice and exploit CWG 2118 for reflection. Define to 0 to override PFR choice and disable CWG 2118 usage.

PFR_USE_STD_MAKE_INTEGRAL_SEQUENCE

Define to 0 if you are hit by the template instantiation depth issues with std::make_integer_sequence and wish to use PFR version of that metafunction. Define to 1 to override PFR detection logic.

PFR_HAS_GUARANTEED_COPY_ELISION

Define to 0 if your compiler does not implement C++17 guaranteed copy elision properly and fails to reflect aggregates with non-movable fields. Define to 1 to override PFR detection logic.

PFR_ENABLE_IMPLICIT_REFLECTION

Define to 0 if you are hit by lots of non-effective choices made by implicitly reflection. Define to 1 to override PFR detection logic.

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 pfr/config.hpp header defines the PFR_ENABLED macro equal to 0. Defining this macro as 0 before including the header disables the PFR library.


Details on Limitations

The PFRs reflection has some limitations that depend on a C++ Standard and compiler capabilities:

The PFRs extraction of field name has some limitations that depend on a C++ Standard and compiler capabilities:

Adjusting PFR_CORE_NAME_PARSING

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:

  1. Build test/core_name/print_name.cpp with your compiler and run it
  2. Define PFR_CORE_NAME_PARSING to (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
  3. Check that test/core_name/print_name.cpp returns "user_defined_field"
  4. If it does not return 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
  5. (optional, but highly recommended) create ticket with feature request to add your compiler to supported compilers list. Include parameters provided to PFR_CORE_NAME_PARSING macro and the initial output of test/core_name/print_name.cpp.

PrevUpHomeNext