Short description:
-
at compile-time: use aggregate initialization to detect fields count in
user-provided structure
-
PFR_USE_CPP17 == 1:
-
at compile-time: structured bindings are used to decompose
a type
T
to
known amount of fields
-
PFR_USE_CPP17 == 0 && PFR_USE_LOOPHOLE
== 1:
-
at compile-time: use aggregate initialization to detect fields
count in user-provided structure
-
at compile-time: make a structure that is convertible to anything
and remember types it has been converted to during aggregate
initialization of user-provided structure
-
at compile-time: using knowledge from previous steps create
a tuple with exactly the same layout as in user-provided structure
-
at compile-time: find offsets for each field in user-provided
structure using the tuple from previous step
-
at run-time: get pointer to each field, knowing the structure
address and each field offset
-
at run-time: a tuple of references to fields is returned =>
all the tuple methods are available for the structure
-
PFR_USE_CPP17 == 0 && PFR_USE_LOOPHOLE
== 0:
-
at compile-time: let
I
be is an index of current field, it equals 0
-
at run-time: T
is constructed and field I
is aggregate initialized using a separate instance of structure
that is convertible to anything
|
Note |
Additional care is taken to make sure that all the information
about T is
available to the compiler and that operations on T have no side effects,
so the compiler can optimize away the unnecessary temporary
objects.
|
-
at compile-time:
I
+= 1
-
at compile-time: if
I
does not equal fields count goto step c.
from inside of the conversion operator of the structure that
is convertible to anything
-
at compile-time: using knowledge from previous steps create
a tuple with exactly the same layout as in user-provided structure
-
at compile-time: find offsets for each field in user-provided
structure using the tuple from previous step
-
at run-time: get pointer to each field, knowing the structure
address and each field offset
-
at run-time: a tuple of references to fields is returned => all the
tuple methods are available for the structure
Long description of some basics: Antony
Polukhin: Better C++14 reflections. Long description of some basics
of C++14 with PFR_USE_LOOPHOLE
== 0: Antony Polukhin:
C++14 Reflections Without Macros, Markup nor External Tooling. Description
of the PFR_USE_LOOPHOLE == 1 technique by
its inventor Alexandr Poltavsky in
his blog.