From 4a973c5eb455bc41b767fb1916adc1066444636f Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Wed, 14 Feb 2024 21:00:23 +0300 Subject: [PATCH] Update docs by not using is_aggregate (fixes #158) and by describing the get_name implementation (fixes #150) --- doc/pfr.qbk | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/pfr.qbk b/doc/pfr.qbk index 156cc65c..a06f212b 100644 --- a/doc/pfr.qbk +++ b/doc/pfr.qbk @@ -161,7 +161,7 @@ void Write(Writer& writer, int value); void Write(Writer& writer, std::string_view value); template -std::enable_if_t> Write(Writer& writer, const T& value) { +std::enable_if_t> Write(Writer& writer, const T& value) { boost::pfr::for_each_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] +[h2 Fields count detection and getting references to members] + Short description: # 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]. 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 `. + 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] [section Acknowledgements]