Skip to content

Commit

Permalink
Update docs by not using is_aggregate (fixes #158) and by describing …
Browse files Browse the repository at this point in the history
…the get_name implementation (fixes #150)
  • Loading branch information
apolukhin committed Feb 14, 2024
1 parent 4c15f21 commit 4a973c5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion doc/pfr.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void Write(Writer& writer, int value);
void Write(Writer& writer, std::string_view value);

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(
value, [&writer](const auto& field) { Write(writer, field); });
}
Expand Down Expand Up @@ -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
Expand All @@ -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 <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]

[section Acknowledgements]
Expand Down

0 comments on commit 4a973c5

Please sign in to comment.