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 a snapshot of the master branch, built from commit c89e626766.
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.

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

Boost.PFRs extraction of field name works with only SimpleAggregate types.

Configuration Macro

By default Boost.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 27.2. Macros

Macro name

Effect

BOOST_PFR_USE_CPP17

Define to 1 if you wish to override Boost.PFR choice and use C++17 structured bindings for reflection. Define to 0 to override Boost.PFR choice and disable C++17 structured bindings usage.

BOOST_PFR_USE_LOOPHOLE

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

BOOST_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 Boost.PFR version of that metafunction. Define to 1 to override Boost.PFR detection logic.

BOOST_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 Boost.PFR detection logic.

BOOST_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 Boost.PFR detection logic.

BOOST_PFR_CORE_NAME_ENABLED

On platforms where field name extraction is not supported, the 'boost/pfr/config.hpp' header defines the BOOST_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.

BOOST_PFR_FUNCTION_SIGNATURE

For known compilers defined to a compiler specific macro, that outputs the whole function signature including non-type template parameters.

BOOST_PFR_CORE_NAME_PARSING

Describes extraction of field name from BOOST_PFR_FUNCTION_SIGNATURE macro. See details below.

BOOST_PFR_ENABLED

On platforms where Boost.PFR is not supported, the boost/pfr/config.hpp header defines the BOOST_PFR_ENABLED macro equal to 0. Defining this macro as 0 before including the header disables the Boost.PFR library.


Details on Limitations

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

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

Adjusting BOOST_PFR_CORE_NAME_PARSING

BOOST_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 BOOST_PFR_CORE_NAME_PARSING.

To do that:

  1. Build test/core_name/print_name.cpp with your compiler and run it
  2. Define BOOST_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 BOOST_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 BOOST_PFR_CORE_NAME_PARSING macro and the initial output of test/core_name/print_name.cpp.

PrevUpHomeNext