161 lines
9.0 KiB
HTML
161 lines
9.0 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>How it works</title>
|
||
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
||
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
|
||
<link rel="up" href="../boost_pfr.html" title="Chapter 28. Boost.PFR 2.0">
|
||
<link rel="prev" href="limitations_and_configuration.html" title="Limitations and Configuration">
|
||
<link rel="next" href="acknowledgements.html" title="Acknowledgements">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<table cellpadding="2" width="100%"><tr>
|
||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
|
||
<td align="center"><a href="../../../index.html">Home</a></td>
|
||
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||
<td align="center"><a href="../../../more/index.htm">More</a></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="limitations_and_configuration.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_pfr.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="boost_pfr.how_it_works"></a><a class="link" href="how_it_works.html" title="How it works">How it works</a>
|
||
</h2></div></div></div>
|
||
<p>
|
||
Short description:
|
||
</p>
|
||
<div class="orderedlist"><ol class="orderedlist" type="1">
|
||
<li class="listitem">
|
||
at compile-time: use aggregate initialization to detect fields count in
|
||
user-provided structure
|
||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||
<li class="listitem">
|
||
<span class="bold"><strong>BOOST_PFR_USE_CPP17 == 1</strong></span>:
|
||
<div class="orderedlist"><ol class="orderedlist" type="a"><li class="listitem">
|
||
at compile-time: structured bindings are used to decompose
|
||
a type <code class="computeroutput"><span class="identifier">T</span></code> to
|
||
known amount of fields
|
||
</li></ol></div>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="bold"><strong>BOOST_PFR_USE_CPP17 == 0 && BOOST_PFR_USE_LOOPHOLE
|
||
== 1</strong></span>:
|
||
<div class="orderedlist"><ol class="orderedlist" type="a">
|
||
<li class="listitem">
|
||
at compile-time: use aggregate initialization to detect fields
|
||
count in user-provided structure
|
||
</li>
|
||
<li class="listitem">
|
||
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
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: using knowledge from previous steps create
|
||
a tuple with exactly the same layout as in user-provided structure
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: find offsets for each field in user-provided
|
||
structure using the tuple from previous step
|
||
</li>
|
||
<li class="listitem">
|
||
at run-time: get pointer to each field, knowing the structure
|
||
address and each field offset
|
||
</li>
|
||
<li class="listitem">
|
||
at run-time: a tuple of references to fields is returned =>
|
||
all the tuple methods are available for the structure
|
||
</li>
|
||
</ol></div>
|
||
</li>
|
||
<li class="listitem">
|
||
<span class="bold"><strong>BOOST_PFR_USE_CPP17 == 0 && BOOST_PFR_USE_LOOPHOLE
|
||
== 0</strong></span>:
|
||
<div class="orderedlist"><ol class="orderedlist" type="a">
|
||
<li class="listitem">
|
||
at compile-time: let <code class="computeroutput"><span class="identifier">I</span></code>
|
||
be is an index of current field, it equals 0
|
||
</li>
|
||
<li class="listitem">
|
||
<p class="simpara">
|
||
at run-time: <code class="computeroutput"><span class="identifier">T</span></code>
|
||
is constructed and field <code class="computeroutput"><span class="identifier">I</span></code>
|
||
is aggregate initialized using a separate instance of structure
|
||
that is convertible to anything
|
||
</p>
|
||
<div class="note"><table border="0" summary="Note">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
|
||
<th align="left">Note</th>
|
||
</tr>
|
||
<tr><td align="left" valign="top"><p>
|
||
Additional care is taken to make sure that all the information
|
||
about <code class="computeroutput"><span class="identifier">T</span></code> is
|
||
available to the compiler and that operations on <code class="computeroutput"><span class="identifier">T</span></code> have no side effects,
|
||
so the compiler can optimize away the unnecessary temporary
|
||
objects.
|
||
</p></td></tr>
|
||
</table></div>
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: <code class="computeroutput"><span class="identifier">I</span>
|
||
<span class="special">+=</span> <span class="number">1</span></code>
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: if <code class="computeroutput"><span class="identifier">I</span></code>
|
||
does not equal fields count goto step <em class="replaceable"><code>c.</code></em>
|
||
from inside of the conversion operator of the structure that
|
||
is convertible to anything
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: using knowledge from previous steps create
|
||
a tuple with exactly the same layout as in user-provided structure
|
||
</li>
|
||
<li class="listitem">
|
||
at compile-time: find offsets for each field in user-provided
|
||
structure using the tuple from previous step
|
||
</li>
|
||
<li class="listitem">
|
||
at run-time: get pointer to each field, knowing the structure
|
||
address and each field offset
|
||
</li>
|
||
</ol></div>
|
||
</li>
|
||
</ul></div>
|
||
</li>
|
||
<li class="listitem">
|
||
at run-time: a tuple of references to fields is returned => all the
|
||
tuple methods are available for the structure
|
||
</li>
|
||
</ol></div>
|
||
<p>
|
||
Long description of some basics: <a href="https://youtu.be/UlNUNxLtBI0" target="_top">Antony
|
||
Polukhin: Better C++14 reflections</a>. Long description of some basics
|
||
of C++14 with <a class="link" href="limitations_and_configuration.html" title="Limitations and Configuration"><span class="bold"><strong>BOOST_PFR_USE_LOOPHOLE == 0</strong></span></a>: <a href="https://youtu.be/abdeAew3gmQ" target="_top">Antony
|
||
Polukhin: C++14 Reflections Without Macros, Markup nor External Tooling</a>.
|
||
Description of the <span class="bold"><strong>BOOST_PFR_USE_LOOPHOLE == 1</strong></span>
|
||
technique by its inventor Alexandr Poltavsky <a href="http://alexpolt.github.io/type-loophole.html" target="_top">in
|
||
his blog</a>.
|
||
</p>
|
||
</div>
|
||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||
<td align="left"></td>
|
||
<td align="right"><div class="copyright-footer">Copyright © 2016-2021 Antony Polukhin<p>
|
||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||
</p>
|
||
</div></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="limitations_and_configuration.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_pfr.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
|
||
</div>
|
||
</body>
|
||
</html>
|