2
0
mirror of https://github.com/boostorg/pfr.git synced 2026-01-19 04:22:13 +00:00

Update docs by not using is_aggregate (fixes #158) and by describing the get_name implementation (fixes #150)

This commit is contained in:
Antony Polukhin
2024-02-14 21:00:23 +03:00
parent 4c15f217f4
commit 4a973c5eb4

View File

@@ -161,7 +161,7 @@ void Write(Writer& writer, int value);
void Write(Writer& writer, std::string_view value); void Write(Writer& writer, std::string_view value);
template <typename T> template <typename T>
std::enable_if_t<std::is_aggregate_v<T>> Write(Writer& writer, const T& value) { std::enable_if_t<boost::pfr::is_implicitly_reflectable_v<T>> Write(Writer& writer, const T& value) {
boost::pfr::for_each_field( boost::pfr::for_each_field(
value, [&writer](const auto& field) { Write(writer, field); }); value, [&writer](const auto& field) { Write(writer, field); });
} }
@@ -551,6 +551,8 @@ parameters provided to `BOOST_PFR_CORE_NAME_PARSING` macro [*and] the initial ou
[section How it works] [section How it works]
[h2 Fields count detection and getting references to members]
Short description: Short description:
# at compile-time: use aggregate initialization to detect fields count in user-provided structure # at compile-time: use aggregate initialization to detect fields count in user-provided structure
@@ -577,6 +579,17 @@ Long description of some basics: [@https://youtu.be/UlNUNxLtBI0 Antony Polukhin:
Long description of some basics of C++14 with [link boost_pfr.limitations_and_configuration [*BOOST_PFR_USE_LOOPHOLE == 0]]: [@https://youtu.be/abdeAew3gmQ Antony Polukhin: C++14 Reflections Without Macros, Markup nor External Tooling]. Long description of some basics of C++14 with [link boost_pfr.limitations_and_configuration [*BOOST_PFR_USE_LOOPHOLE == 0]]: [@https://youtu.be/abdeAew3gmQ Antony Polukhin: C++14 Reflections Without Macros, Markup nor External Tooling].
Description of the [*BOOST_PFR_USE_LOOPHOLE == 1] technique by its inventor Alexandr Poltavsky [@http://alexpolt.github.io/type-loophole.html in his blog]. Description of the [*BOOST_PFR_USE_LOOPHOLE == 1] technique by its inventor Alexandr Poltavsky [@http://alexpolt.github.io/type-loophole.html in his blog].
[h2 Field name retrieval]
# at compile-time:
* Get references to members of an object of type `T` in `constexpr` function
* Feed the reference from previous as a template parameter to a `constexpr` function with `template <auto member_ptr>`.
That function returns `__PRETTY_FUNCTION__` or some other vendor specific macro that prints the whole name of a function
along with the template arguments.
* The returned value from previous step contains the member name ([@https://godbolt.org/z/K4aWdcE9G godbolt example]). Do some
compiler specific parsing of the value and make a `std::string_view` that contains only the member name.
# at run-time: return the `std::string_view` with the member name.
[endsect] [endsect]
[section Acknowledgements] [section Acknowledgements]