group__group-Struct.html 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <!--
  2. Copyright Louis Dionne 2013-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!-- boost-no-inspect -->
  7. <!-- HTML header for doxygen 1.8.9.1-->
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  12. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  13. <meta name="generator" content="Doxygen 1.8.15"/>
  14. <title>Boost.Hana: Struct</title>
  15. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  16. <script type="text/javascript" src="jquery.js"></script>
  17. <script type="text/javascript" src="dynsections.js"></script>
  18. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  19. <script type="text/javascript" src="resize.js"></script>
  20. <script type="text/javascript" src="navtreedata.js"></script>
  21. <script type="text/javascript" src="navtree.js"></script>
  22. <script type="text/javascript">
  23. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  24. $(document).ready(initResizable);
  25. /* @license-end */</script>
  26. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  27. <script type="text/javascript" src="search/searchdata.js"></script>
  28. <script type="text/javascript" src="search/search.js"></script>
  29. <script type="text/javascript">
  30. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  31. $(document).ready(function() { init_search(); });
  32. /* @license-end */
  33. </script>
  34. <script type="text/x-mathjax-config">
  35. MathJax.Hub.Config({
  36. extensions: ["tex2jax.js"],
  37. jax: ["input/TeX","output/HTML-CSS"],
  38. });
  39. // Copyright Louis Dionne 2013-2017
  40. // Distributed under the Boost Software License, Version 1.0.
  41. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  42. MathJax.Hub.Config({
  43. "HTML-CSS": {
  44. linebreaks: {
  45. automatic: true,
  46. width: "75% container"
  47. }
  48. }
  49. });
  50. </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
  51. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  52. <!-- Additional javascript for drawing charts. -->
  53. <script type="text/javascript" src="highcharts.js"></script>
  54. <script type="text/javascript" src="highcharts-data.js"></script>
  55. <script type="text/javascript" src="highcharts-exporting.js"></script>
  56. <script type="text/javascript" src="chart.js"></script>
  57. <script type="text/javascript" src="hana.js"></script>
  58. </head>
  59. <body>
  60. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  61. <div id="titlearea">
  62. <table cellspacing="0" cellpadding="0">
  63. <tbody>
  64. <tr style="height: 56px;">
  65. <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  66. <td style="padding-left: 0.5em;">
  67. <div id="projectname">Boost.Hana
  68. &#160;<span id="projectnumber">1.6.0</span>
  69. </div>
  70. <div id="projectbrief">Your standard library for metaprogramming</div>
  71. </td>
  72. <td> <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <!-- end header part -->
  92. <!-- Generated by Doxygen 1.8.15 -->
  93. <script type="text/javascript">
  94. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  95. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  96. /* @license-end */
  97. </script>
  98. </div><!-- top -->
  99. <div id="side-nav" class="ui-resizable side-nav-resizable">
  100. <div id="nav-tree">
  101. <div id="nav-tree-contents">
  102. <div id="nav-sync" class="sync"></div>
  103. </div>
  104. </div>
  105. <div id="splitbar" style="-moz-user-select:none;"
  106. class="ui-resizable-handle">
  107. </div>
  108. </div>
  109. <script type="text/javascript">
  110. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  111. $(document).ready(function(){initNavTree('group__group-Struct.html','');});
  112. /* @license-end */
  113. </script>
  114. <div id="doc-content">
  115. <!-- window showing the filter options -->
  116. <div id="MSearchSelectWindow"
  117. onmouseover="return searchBox.OnSearchSelectShow()"
  118. onmouseout="return searchBox.OnSearchSelectHide()"
  119. onkeydown="return searchBox.OnSearchSelectKey(event)">
  120. </div>
  121. <!-- iframe showing the search results (closed by default) -->
  122. <div id="MSearchResultsWindow">
  123. <iframe src="javascript:void(0)" frameborder="0"
  124. name="MSearchResults" id="MSearchResults">
  125. </iframe>
  126. </div>
  127. <div class="header">
  128. <div class="summary">
  129. <a href="#func-members">Functions</a> &#124;
  130. <a href="#var-members">Variables</a> </div>
  131. <div class="headertitle">
  132. <div class="title">Struct<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  133. </div><!--header-->
  134. <div class="contents">
  135. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  136. <p>The <code>Struct</code> concept represents <code>struct</code>-like user-defined types. </p>
  137. <p>The <code>Struct</code> concept allows restricted compile-time reflection over user-defined types. In particular, it allows accessing the names of the members of a user-defined type, and also the value of those members. <code>Struct</code>s can also be folded, searched and converted to some types of containers, where more advanced transformations can be performed.</p>
  138. <p>While all types can <em>in theory</em> be made <code>Struct</code>s, only a subset of them are actually interesting to see as such. More precisely, it is only interesting to make a type a <code>Struct</code> when it is conceptually a C++ <code>struct</code>, i.e. a mostly dumb aggregate of named data. The way this data is accessed is mostly unimportant to the <code>Struct</code> concept; it could be through getters and setters, through public members, through non-member functions or it could even be generated on-the-fly. The important part, which is made precise below, is that those accessor methods should be move-independent.</p>
  139. <p>Another way to see a <code>Struct</code> is as a map where the keys are the names of the members and the values are the values of those members. However, there are subtle differences like the fact that one can't add a member to a <code>Struct</code>, and also that the order of the members inside a <code>Struct</code> plays a role in determining the equality of <code>Struct</code>s, which is not the case for maps.</p>
  140. <h2>Minimal complete definition </h2>
  141. <p><code>accessors</code></p>
  142. <p>A model of <code>Struct</code> is created by specifying a sequence of key/value pairs with the <code>accessors</code> function. The first element of a pair in this sequence represents the "name" of a member of the <code>Struct</code>, while the second element is a function which retrieves this member from an object. The "names" do not have to be in any special form; they just have to be compile-time <code>Comparable</code>. For example, it is common to provide "names" that are <code><a class="el" href="structboost_1_1hana_1_1string.html" title="Compile-time string.">hana::string</a></code>s representing the actual names of the members, but one could provide <code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">hana::integral_constant</a></code>s just as well. The values must be functions which, when given an object, retrieve the appropriate member from it.</p>
  143. <p>There are several ways of providing the <code>accessors</code> method, some of which are more flexible and others which are more convenient. First, one can define it through tag-dispatching, as usual. </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> std::string name;</div><div class="line"> <span class="keywordtype">int</span> age;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">// The keys can be anything as long as they are compile-time comparable.</span></div><div class="line">constexpr <span class="keyword">auto</span> name = hana::integral_c&lt;std::string Person::*, &amp;Person::name&gt;;</div><div class="line">constexpr <span class="keyword">auto</span> age = hana::string_c&lt;&#39;a&#39;, &#39;g&#39;, &#39;e&#39;&gt;;</div><div class="line"></div><div class="line"><span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>hana {</div><div class="line"> <span class="keyword">template</span> &lt;&gt;</div><div class="line"> <span class="keyword">struct </span>accessors_impl&lt;Person&gt; {</div><div class="line"> <span class="keyword">static</span> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>() {</div><div class="line"> <span class="keywordflow">return</span> make_tuple(</div><div class="line"> make_pair(name, [](<span class="keyword">auto</span>&amp;&amp; p) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">id</a>(std::forward&lt;decltype(p)&gt;(p).name);</div><div class="line"> }),</div><div class="line"> make_pair(age, [](<span class="keyword">auto</span>&amp;&amp; p) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">id</a>(std::forward&lt;decltype(p)&gt;(p).age);</div><div class="line"> })</div><div class="line"> );</div><div class="line"> }</div><div class="line"> };</div><div class="line">}}</div></div><!-- fragment --><p> Secondly, it is possible to provide a nested <code>hana_accessors_impl</code> type, which should be equivalent to a specialization of <code>accessors_impl</code> for tag-dispatching. However, for a type <code>S</code>, this technique only works when the data type of <code>S</code> is <code>S</code> itself, which is the case unless you explicitly asked for something else. </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> std::string name;</div><div class="line"> <span class="keywordtype">int</span> age;</div><div class="line"></div><div class="line"> <span class="keyword">struct </span>hana_accessors_impl {</div><div class="line"> <span class="keyword">static</span> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>() {</div><div class="line"> <span class="keywordflow">return</span> boost::hana::make_tuple(</div><div class="line"> boost::hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>),</div><div class="line"> [](<span class="keyword">auto</span>&amp;&amp; p) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">boost::hana::id</a>(std::forward&lt;decltype(p)&gt;(p).name);</div><div class="line"> }),</div><div class="line"> boost::hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>),</div><div class="line"> [](<span class="keyword">auto</span>&amp;&amp; p) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">boost::hana::id</a>(std::forward&lt;decltype(p)&gt;(p).age);</div><div class="line"> })</div><div class="line"> );</div><div class="line"> }</div><div class="line"> };</div><div class="line">};</div></div><!-- fragment --><p> Finally, the most convenient (but least flexible) option is to use the <code>BOOST_HANA_DEFINE_STRUCT</code>, the <code>BOOST_HANA_ADAPT_STRUCT</code> or the <code>BOOST_HANA_ADAPT_ADT</code> macro, which provide a minimal syntactic overhead. See the documentation of these macros for details on how to use them.</p>
  144. <p>Also note that it is not important that the accessor functions retrieve an actual member of the struct (e.g. <code>x.member</code>). Indeed, an accessor function could call a custom getter or even compute the value of the member on the fly: </p><div class="fragment"><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> Person(std::string <span class="keyword">const</span>&amp; name, <span class="keywordtype">int</span> age) : name_(name), age_(age) { }</div><div class="line"></div><div class="line"> std::string <span class="keyword">const</span>&amp; get_name()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> name_; }</div><div class="line"> <span class="keywordtype">int</span> get_age()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> age_; }</div><div class="line"></div><div class="line"><span class="keyword">private</span>:</div><div class="line"> std::string name_;</div><div class="line"> <span class="keywordtype">int</span> age_;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>hana {</div><div class="line"> <span class="keyword">template</span> &lt;&gt;</div><div class="line"> <span class="keyword">struct </span>accessors_impl&lt;Person&gt; {</div><div class="line"> <span class="keyword">static</span> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>() {</div><div class="line"> <span class="keywordflow">return</span> make_tuple(</div><div class="line"> make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), [](<span class="keyword">auto</span>&amp;&amp; p) -&gt; std::string <span class="keyword">const</span>&amp; {</div><div class="line"> <span class="keywordflow">return</span> p.get_name();</div><div class="line"> }),</div><div class="line"> make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), [](<span class="keyword">auto</span>&amp;&amp; p) {</div><div class="line"> <span class="keywordflow">return</span> p.get_age();</div><div class="line"> })</div><div class="line"> );</div><div class="line"> }</div><div class="line"> };</div><div class="line">}}</div></div><!-- fragment --><p> The only important thing is that the accessor functions are move-independent, a notion which is defined below.</p>
  145. <p><a class="anchor" id="move-independence"></a></p><h2>Move-independence </h2>
  146. <p>The notion of move-independence presented here defines rigorously when it is legitimate to "double-move" from an object.</p>
  147. <p>A collection of functions <code>f1, ..., fn</code> sharing the same domain is said to be <em>move-independent</em> if for every fresh (not moved-from) object <code>x</code> in the domain, any permutation of the following statements is valid and leaves the <code>zk</code> objects in a fresh (not moved-from) state: </p><div class="fragment"><div class="line"><span class="keyword">auto</span> z1 = f1(std::move(x));</div><div class="line">...</div><div class="line">auto zn = fn(std::move(x));</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>In the special case where some functions return objects that can't be bound to with <code>auto zk =</code> (like <code>void</code> or a non-movable, non-copyable type), just pretend the return value is ignored.</dd></dl>
  148. <p>Intuitively, this ensures that we can treat <code>f1, ..., fn</code> as "accessors" that decompose <code>x</code> into independent subobjects, and that do so without moving from <code>x</code> more than that subobject. This is important because it allows us to optimally decompose <code>Struct</code>s into their subparts inside the library.</p>
  149. <h2>Laws </h2>
  150. <p>For any <code>Struct</code> <code>S</code>, the accessors in the <code>accessors&lt;S&gt;()</code> sequence must be move-independent, as defined above.</p>
  151. <h2>Refined concepts </h2>
  152. <ol type="1">
  153. <li><code>Comparable</code> (free model)<br />
  154. <code>Struct</code>s are required to be <code>Comparable</code>. Specifically, two <code>Struct</code>s of the same data type <code>S</code> must be equal if and only if all of their members are equal. By default, a model of <code>Comparable</code> doing just that is provided for models of <code>Struct</code>. In particular, note that the comparison of the members is made in the same order as they appear in the <code><a class="el" href="group__group-Struct.html#gad301dd8e9fb4639d7874619c97d6d427" title="Returns a Sequence containing the members of a Struct.Given a Struct object, members returns a Sequen...">hana::members</a></code> sequence. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="keys_8hpp.html">boost/hana/keys.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30}, kevin{<span class="stringliteral">&quot;Kevin&quot;</span>, 20};</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(john, john));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(john, kevin));</div><div class="line">}</div></div><!-- fragment --></li>
  155. <li><code>Foldable</code> (free model)<br />
  156. A <code>Struct</code> can be folded by considering it as a list of pairs each containing the name of a member and the value associated to that member, in the same order as they appear in the <code><a class="el" href="group__group-Struct.html#gad301dd8e9fb4639d7874619c97d6d427" title="Returns a Sequence containing the members of a Struct.Given a Struct object, members returns a Sequen...">hana::members</a></code> sequence. By default, a model of <code>Foldable</code> doing just that is provided for models of the <code>Struct</code> concept. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="fold__left_8hpp.html">boost/hana/fold_left.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="second_8hpp.html">boost/hana/second.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Kitten {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Kitten,</div><div class="line"> (<span class="keywordtype">int</span>, extremely_cute),</div><div class="line"> (<span class="keywordtype">int</span>, cute),</div><div class="line"> (<span class="keywordtype">int</span>, not_so_cute)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> constexpr Kitten kitten{5, 10, 0};</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Foldable.html#ga38c6b3f6b1cbadb9b8432a05ff16b7d2">hana::fold_left</a>(kitten, 0, [](<span class="keyword">auto</span> total, <span class="keyword">auto</span> member) {</div><div class="line"> <span class="comment">// first(member) is the name of the member, here</span></div><div class="line"> <span class="comment">// &quot;extremely_cute&quot;, or &quot;cute&quot; or &quot;not_so_cute&quot;,</span></div><div class="line"> <span class="comment">// and second(member) is its value.</span></div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-Product.html#ga7bb979d59ffc3ab862cb7d9dc7730077">hana::second</a>(member) + total;</div><div class="line"> }) == (5 + 10 + 0)</div><div class="line"> );</div><div class="line">}</div></div><!-- fragment --> Being a model of <code>Foldable</code> makes it possible to turn a <code>Struct</code> into basically any <code>Sequence</code>, but also into a <code><a class="el" href="structboost_1_1hana_1_1map.html" title="Basic associative container requiring unique, Comparable and Hashable keys.">hana::map</a></code> by simply using the <code>to&lt;...&gt;</code> function! <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="core_2to_8hpp.html">boost/hana/core/to.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="map_8hpp.html">boost/hana/map.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="pair_8hpp.html">boost/hana/pair.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30u};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to&lt;hana::map_tag&gt;(john) == hana::make_map(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30u)</div><div class="line"> ));</div><div class="line">}</div></div><!-- fragment --></li>
  157. <li><code>Searchable</code> (free model)<br />
  158. A <code>Struct</code> can be searched by considering it as a map where the keys are the names of the members of the <code>Struct</code>, and the values are the members associated to those names. By default, a model of <code>Searchable</code> is provided for any model of the <code>Struct</code> concept. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="accessors_8hpp.html">boost/hana/accessors.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="all__of_8hpp.html">boost/hana/all_of.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="find_8hpp.html">boost/hana/find.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="second_8hpp.html">boost/hana/second.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30};</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>)) == hana::just(<span class="stringliteral">&quot;John&quot;</span>)</div><div class="line"> );</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;foobar&quot;</span>)) == hana::nothing</div><div class="line"> );</div><div class="line"></div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Searchable.html#ga3a168950082f38afd9edf256f336c8ba">hana::all_of</a>(hana::accessors&lt;Person&gt;(), [&amp;](<span class="keyword">auto</span> a) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-Product.html#ga7bb979d59ffc3ab862cb7d9dc7730077">hana::second</a>(a)(john) == <a class="code" href="group__group-Product.html#ga7bb979d59ffc3ab862cb7d9dc7730077">hana::second</a>(a)(john);</div><div class="line"> })</div><div class="line"> );</div><div class="line"></div><div class="line"> <span class="comment">// the above is equivalent to:</span></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(john, john));</div><div class="line">}</div></div><!-- fragment --> </li>
  159. </ol>
  160. <table class="memberdecls">
  161. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
  162. Functions</h2></td></tr>
  163. <tr class="memitem:ga141761435a7826b3cbe646b4f59eaf0a"><td class="memItemLeft" align="right" valign="top">auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#ga141761435a7826b3cbe646b4f59eaf0a">boost::hana::BOOST_HANA_ADAPT_ADT</a> (...)</td></tr>
  164. <tr class="memdesc:ga141761435a7826b3cbe646b4f59eaf0a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Defines a model of <code>Struct</code> with the given accessors.Using this macro at <em>global scope</em> will define a model of the <code>Struct</code> concept for the given type. This can be used to easily adapt existing user-defined types in a ad-hoc manner. Unlike <code>BOOST_HANA_ADAPT_STRUCT</code>, this macro requires specifying the way to retrieve each member by providing a function that does the extraction. <a href="group__group-Struct.html#ga141761435a7826b3cbe646b4f59eaf0a">More...</a><br /></td></tr>
  165. <tr class="separator:ga141761435a7826b3cbe646b4f59eaf0a"><td class="memSeparator" colspan="2">&#160;</td></tr>
  166. <tr class="memitem:gaba3b4d2cf342bfca773e90fc20bfae91"><td class="memItemLeft" align="right" valign="top">auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#gaba3b4d2cf342bfca773e90fc20bfae91">boost::hana::BOOST_HANA_ADAPT_STRUCT</a> (...)</td></tr>
  167. <tr class="memdesc:gaba3b4d2cf342bfca773e90fc20bfae91"><td class="mdescLeft">&#160;</td><td class="mdescRight">Defines a model of <code>Struct</code> with the given members.Using this macro at <em>global scope</em> will define a model of the <code>Struct</code> concept for the given type. This can be used to easily adapt existing user-defined types in a ad-hoc manner. Unlike the <code>BOOST_HANA_DEFINE_STRUCT</code> macro, this macro does not require the types of the members to be specified. <a href="group__group-Struct.html#gaba3b4d2cf342bfca773e90fc20bfae91">More...</a><br /></td></tr>
  168. <tr class="separator:gaba3b4d2cf342bfca773e90fc20bfae91"><td class="memSeparator" colspan="2">&#160;</td></tr>
  169. <tr class="memitem:gab9efb238a82207d91643994c5295cf8c"><td class="memItemLeft" align="right" valign="top">auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">boost::hana::BOOST_HANA_DEFINE_STRUCT</a> (...)</td></tr>
  170. <tr class="memdesc:gab9efb238a82207d91643994c5295cf8c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Defines members of a structure, while at the same time modeling <code>Struct</code>.Using this macro in the body of a user-defined type will define the given members inside that type, and will also provide a model of the <code>Struct</code> concept for that user-defined type. This macro is often the easiest way to define a model of the <code>Struct</code> concept. <a href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">More...</a><br /></td></tr>
  171. <tr class="separator:gab9efb238a82207d91643994c5295cf8c"><td class="memSeparator" colspan="2">&#160;</td></tr>
  172. </table><table class="memberdecls">
  173. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  174. Variables</h2></td></tr>
  175. <tr class="memitem:ga983a55dbd93d766fd37689ea32e4ddfb"><td class="memTemplParams" colspan="2">template&lt;typename S &gt; </td></tr>
  176. <tr class="memitem:ga983a55dbd93d766fd37689ea32e4ddfb"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">boost::hana::accessors</a></td></tr>
  177. <tr class="memdesc:ga983a55dbd93d766fd37689ea32e4ddfb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Sequence</code> of pairs representing the accessors of the data structure.Given a <code>Struct</code> <code>S</code>, <code>accessors&lt;S&gt;()</code> is a <code>Sequence</code> of <code>Product</code>s where the first element of each pair is the "name" of a member of the <code>Struct</code>, and the second element of each pair is a function that can be used to access that member when given an object of the proper data type. As described in the global documentation for <code>Struct</code>, the accessor functions in this sequence must be move-independent. <a href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">More...</a><br /></td></tr>
  178. <tr class="separator:ga983a55dbd93d766fd37689ea32e4ddfb"><td class="memSeparator" colspan="2">&#160;</td></tr>
  179. <tr class="memitem:gaf8c7199742581e6e66c8397def68e2d3"><td class="memItemLeft" align="right" valign="top">constexpr keys_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#gaf8c7199742581e6e66c8397def68e2d3">boost::hana::keys</a> {}</td></tr>
  180. <tr class="memdesc:gaf8c7199742581e6e66c8397def68e2d3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Sequence</code> containing the name of the members of the data structure.Given a <code>Struct</code> object, <code>keys</code> returns a <code>Sequence</code> containing the name of all the members of the <code>Struct</code>, in the same order as they appear in the <code>accessors</code> sequence. <a href="group__group-Struct.html#gaf8c7199742581e6e66c8397def68e2d3">More...</a><br /></td></tr>
  181. <tr class="separator:gaf8c7199742581e6e66c8397def68e2d3"><td class="memSeparator" colspan="2">&#160;</td></tr>
  182. <tr class="memitem:gad301dd8e9fb4639d7874619c97d6d427"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Struct.html#gad301dd8e9fb4639d7874619c97d6d427">boost::hana::members</a></td></tr>
  183. <tr class="memdesc:gad301dd8e9fb4639d7874619c97d6d427"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Sequence</code> containing the members of a <code>Struct</code>.Given a <code>Struct</code> object, <code>members</code> returns a <code>Sequence</code> containing all the members of the <code>Struct</code>, in the same order as their respective accessor appears in the <code>accessors</code> sequence. <a href="group__group-Struct.html#gad301dd8e9fb4639d7874619c97d6d427">More...</a><br /></td></tr>
  184. <tr class="separator:gad301dd8e9fb4639d7874619c97d6d427"><td class="memSeparator" colspan="2">&#160;</td></tr>
  185. </table>
  186. <h2 class="groupheader">Function Documentation</h2>
  187. <a id="ga141761435a7826b3cbe646b4f59eaf0a"></a>
  188. <h2 class="memtitle"><span class="permalink"><a href="#ga141761435a7826b3cbe646b4f59eaf0a">&#9670;&nbsp;</a></span>BOOST_HANA_ADAPT_ADT()</h2>
  189. <div class="memitem">
  190. <div class="memproto">
  191. <table class="memname">
  192. <tr>
  193. <td class="memname">auto boost::hana::BOOST_HANA_ADAPT_ADT </td>
  194. <td>(</td>
  195. <td class="paramtype">&#160;</td>
  196. <td class="paramname"><em>...</em></td><td>)</td>
  197. <td></td>
  198. </tr>
  199. </table>
  200. </div><div class="memdoc">
  201. <p><code>#include &lt;<a class="el" href="fwd_2adapt__adt_8hpp.html">boost/hana/fwd/adapt_adt.hpp</a>&gt;</code></p>
  202. <p>Defines a model of <code>Struct</code> with the given accessors.Using this macro at <em>global scope</em> will define a model of the <code>Struct</code> concept for the given type. This can be used to easily adapt existing user-defined types in a ad-hoc manner. Unlike <code>BOOST_HANA_ADAPT_STRUCT</code>, this macro requires specifying the way to retrieve each member by providing a function that does the extraction. </p>
  203. <dl class="section note"><dt>Note</dt><dd>This macro only works if the tag of the user-defined type <code>T</code> is <code>T</code> itself. This is the case unless you specifically asked for something different; see <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T.">tag_of</a></code>'s documentation.</dd></dl>
  204. <h2>Example </h2>
  205. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="accessors_8hpp.html">boost/hana/accessors.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="adapt__adt_8hpp.html">boost/hana/adapt_adt.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="core_2to_8hpp.html">boost/hana/core/to.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="find_8hpp.html">boost/hana/find.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="first_8hpp.html">boost/hana/first.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="map_8hpp.html">boost/hana/map.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="pair_8hpp.html">boost/hana/pair.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="transform_8hpp.html">boost/hana/transform.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">namespace </span>ns {</div><div class="line"> <span class="keyword">struct </span>Person {</div><div class="line"> <span class="keyword">explicit</span> Person(std::string <span class="keyword">const</span>&amp; name, <span class="keywordtype">int</span> age)</div><div class="line"> : name_(name), age_(age)</div><div class="line"> { }</div><div class="line"> std::string <span class="keyword">const</span>&amp; get_name()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> name_; }</div><div class="line"> <span class="keywordtype">int</span> get_age()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> age_; }</div><div class="line"></div><div class="line"> <span class="keyword">private</span>:</div><div class="line"> std::string name_;</div><div class="line"> <span class="keywordtype">int</span> age_;</div><div class="line"> };</div><div class="line">}</div><div class="line"></div><div class="line"><a class="code" href="group__group-Struct.html#ga141761435a7826b3cbe646b4f59eaf0a">BOOST_HANA_ADAPT_ADT</a>(ns::Person,</div><div class="line"> (name, [](ns::Person <span class="keyword">const</span>&amp; p) { <span class="keywordflow">return</span> p.get_name(); }),</div><div class="line"> (age, [](ns::Person <span class="keyword">const</span>&amp; p) { <span class="keywordflow">return</span> p.get_age(); })</div><div class="line">);</div><div class="line"></div><div class="line"><span class="comment">// The member names are hana::strings:</span></div><div class="line"><span class="keyword">auto</span> names = <a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::accessors&lt;ns::Person&gt;(), <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> names == hana::make_tuple(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>))</div><div class="line">);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> ns::Person john{<span class="stringliteral">&quot;John&quot;</span>, 30}, bob{<span class="stringliteral">&quot;Bob&quot;</span>, 40};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(john, john));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(john, bob));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>)) == hana::just(<span class="stringliteral">&quot;John&quot;</span>));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>)) == hana::just(30));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;foo&quot;</span>)) == hana::nothing);</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_tuple(john) == hana::make_tuple(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_map(john) == hana::make_map(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line">}</div></div><!-- fragment -->
  206. </div>
  207. </div>
  208. <a id="gaba3b4d2cf342bfca773e90fc20bfae91"></a>
  209. <h2 class="memtitle"><span class="permalink"><a href="#gaba3b4d2cf342bfca773e90fc20bfae91">&#9670;&nbsp;</a></span>BOOST_HANA_ADAPT_STRUCT()</h2>
  210. <div class="memitem">
  211. <div class="memproto">
  212. <table class="memname">
  213. <tr>
  214. <td class="memname">auto boost::hana::BOOST_HANA_ADAPT_STRUCT </td>
  215. <td>(</td>
  216. <td class="paramtype">&#160;</td>
  217. <td class="paramname"><em>...</em></td><td>)</td>
  218. <td></td>
  219. </tr>
  220. </table>
  221. </div><div class="memdoc">
  222. <p><code>#include &lt;<a class="el" href="fwd_2adapt__struct_8hpp.html">boost/hana/fwd/adapt_struct.hpp</a>&gt;</code></p>
  223. <p>Defines a model of <code>Struct</code> with the given members.Using this macro at <em>global scope</em> will define a model of the <code>Struct</code> concept for the given type. This can be used to easily adapt existing user-defined types in a ad-hoc manner. Unlike the <code>BOOST_HANA_DEFINE_STRUCT</code> macro, this macro does not require the types of the members to be specified. </p>
  224. <dl class="section note"><dt>Note</dt><dd>This macro only works if the tag of the user-defined type <code>T</code> is <code>T</code> itself. This is the case unless you specifically asked for something different; see <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T.">tag_of</a></code>'s documentation.</dd></dl>
  225. <h2>Example </h2>
  226. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="accessors_8hpp.html">boost/hana/accessors.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="adapt__struct_8hpp.html">boost/hana/adapt_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="core_2to_8hpp.html">boost/hana/core/to.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="find_8hpp.html">boost/hana/find.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="first_8hpp.html">boost/hana/first.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="map_8hpp.html">boost/hana/map.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="pair_8hpp.html">boost/hana/pair.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="transform_8hpp.html">boost/hana/transform.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">namespace </span>ns {</div><div class="line"> <span class="keyword">struct </span>Person {</div><div class="line"> std::string name;</div><div class="line"> <span class="keywordtype">int</span> age;</div><div class="line"> };</div><div class="line">}</div><div class="line"></div><div class="line"><a class="code" href="group__group-Struct.html#gaba3b4d2cf342bfca773e90fc20bfae91">BOOST_HANA_ADAPT_STRUCT</a>(ns::Person,</div><div class="line"> name,</div><div class="line"> age</div><div class="line">);</div><div class="line"></div><div class="line"><span class="comment">// The member names are hana::strings:</span></div><div class="line"><span class="keyword">auto</span> names = <a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::accessors&lt;ns::Person&gt;(), <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> names == hana::make_tuple(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>))</div><div class="line">);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> ns::Person john{<span class="stringliteral">&quot;John&quot;</span>, 30}, bob{<span class="stringliteral">&quot;Bob&quot;</span>, 40};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(john, john));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(john, bob));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>)) == hana::just(<span class="stringliteral">&quot;John&quot;</span>));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>)) == hana::just(30));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;foo&quot;</span>)) == hana::nothing);</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_tuple(john) == hana::make_tuple(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_map(john) == hana::make_map(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line">}</div></div><!-- fragment -->
  227. </div>
  228. </div>
  229. <a id="gab9efb238a82207d91643994c5295cf8c"></a>
  230. <h2 class="memtitle"><span class="permalink"><a href="#gab9efb238a82207d91643994c5295cf8c">&#9670;&nbsp;</a></span>BOOST_HANA_DEFINE_STRUCT()</h2>
  231. <div class="memitem">
  232. <div class="memproto">
  233. <table class="memname">
  234. <tr>
  235. <td class="memname">auto boost::hana::BOOST_HANA_DEFINE_STRUCT </td>
  236. <td>(</td>
  237. <td class="paramtype">&#160;</td>
  238. <td class="paramname"><em>...</em></td><td>)</td>
  239. <td></td>
  240. </tr>
  241. </table>
  242. </div><div class="memdoc">
  243. <p><code>#include &lt;<a class="el" href="fwd_2define__struct_8hpp.html">boost/hana/fwd/define_struct.hpp</a>&gt;</code></p>
  244. <p>Defines members of a structure, while at the same time modeling <code>Struct</code>.Using this macro in the body of a user-defined type will define the given members inside that type, and will also provide a model of the <code>Struct</code> concept for that user-defined type. This macro is often the easiest way to define a model of the <code>Struct</code> concept. </p>
  245. <dl class="section note"><dt>Note</dt><dd>This macro only works if the tag of the user-defined type <code>T</code> is <code>T</code> itself. This is the case unless you specifically asked for something different; see <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T.">tag_of</a></code>'s documentation.</dd></dl>
  246. <h2>Example </h2>
  247. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="accessors_8hpp.html">boost/hana/accessors.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="core_2to_8hpp.html">boost/hana/core/to.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="find_8hpp.html">boost/hana/find.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="first_8hpp.html">boost/hana/first.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="map_8hpp.html">boost/hana/map.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="pair_8hpp.html">boost/hana/pair.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="transform_8hpp.html">boost/hana/transform.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">int</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="comment">// The member names are hana::strings:</span></div><div class="line"><span class="keyword">auto</span> names = <a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::accessors&lt;Person&gt;(), <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> names == hana::make_tuple(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>))</div><div class="line">);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30}, bob{<span class="stringliteral">&quot;Bob&quot;</span>, 40};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(john, john));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(john, bob));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>)) == hana::just(<span class="stringliteral">&quot;John&quot;</span>));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>)) == hana::just(30));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga6b6cdd69942b0fe3bf5254247f9c861e">hana::find</a>(john, BOOST_HANA_STRING(<span class="stringliteral">&quot;foo&quot;</span>)) == hana::nothing);</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_tuple(john) == hana::make_tuple(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::to_map(john) == hana::make_map(</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>), <span class="stringliteral">&quot;John&quot;</span>),</div><div class="line"> hana::make_pair(BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>), 30)</div><div class="line"> ));</div><div class="line">}</div></div><!-- fragment -->
  248. </div>
  249. </div>
  250. <h2 class="groupheader">Variable Documentation</h2>
  251. <a id="ga983a55dbd93d766fd37689ea32e4ddfb"></a>
  252. <h2 class="memtitle"><span class="permalink"><a href="#ga983a55dbd93d766fd37689ea32e4ddfb">&#9670;&nbsp;</a></span>accessors</h2>
  253. <div class="memitem">
  254. <div class="memproto">
  255. <div class="memtemplate">
  256. template&lt;typename S &gt; </div>
  257. <table class="memname">
  258. <tr>
  259. <td class="memname">constexpr auto boost::hana::accessors</td>
  260. </tr>
  261. </table>
  262. </div><div class="memdoc">
  263. <p><code>#include &lt;<a class="el" href="fwd_2accessors_8hpp.html">boost/hana/fwd/accessors.hpp</a>&gt;</code></p>
  264. <b>Initial value:</b><div class="fragment"><div class="line">= []() {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  265. <p>Returns a <code>Sequence</code> of pairs representing the accessors of the data structure.Given a <code>Struct</code> <code>S</code>, <code>accessors&lt;S&gt;()</code> is a <code>Sequence</code> of <code>Product</code>s where the first element of each pair is the "name" of a member of the <code>Struct</code>, and the second element of each pair is a function that can be used to access that member when given an object of the proper data type. As described in the global documentation for <code>Struct</code>, the accessor functions in this sequence must be move-independent. </p>
  266. <h2>Example </h2>
  267. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="accessors_8hpp.html">boost/hana/accessors.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="at_8hpp.html">boost/hana/at.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="first_8hpp.html">boost/hana/first.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="integral__constant_8hpp.html">boost/hana/integral_constant.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="second_8hpp.html">boost/hana/second.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> constexpr <span class="keyword">auto</span> <a class="code" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">accessors</a> = hana::accessors&lt;Person&gt;();</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>(<a class="code" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">accessors</a>[hana::size_c&lt;0&gt;]) == BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>)</div><div class="line"> );</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>(<a class="code" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">accessors</a>[hana::size_c&lt;1&gt;]) == BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>)</div><div class="line"> );</div><div class="line"></div><div class="line"> constexpr <span class="keyword">auto</span> get_name = <a class="code" href="group__group-Product.html#ga7bb979d59ffc3ab862cb7d9dc7730077">hana::second</a>(<a class="code" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">accessors</a>[hana::size_c&lt;0&gt;]);</div><div class="line"> constexpr <span class="keyword">auto</span> get_age = <a class="code" href="group__group-Product.html#ga7bb979d59ffc3ab862cb7d9dc7730077">hana::second</a>(<a class="code" href="group__group-Struct.html#ga983a55dbd93d766fd37689ea32e4ddfb">accessors</a>[hana::size_c&lt;1&gt;]);</div><div class="line"></div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(get_name(john) == <span class="stringliteral">&quot;John&quot;</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(get_age(john) == 30);</div><div class="line">}</div></div><!-- fragment -->
  268. </div>
  269. </div>
  270. <a id="gaf8c7199742581e6e66c8397def68e2d3"></a>
  271. <h2 class="memtitle"><span class="permalink"><a href="#gaf8c7199742581e6e66c8397def68e2d3">&#9670;&nbsp;</a></span>keys</h2>
  272. <div class="memitem">
  273. <div class="memproto">
  274. <table class="mlabels">
  275. <tr>
  276. <td class="mlabels-left">
  277. <table class="memname">
  278. <tr>
  279. <td class="memname">constexpr auto boost::hana::keys {}</td>
  280. </tr>
  281. </table>
  282. </td>
  283. <td class="mlabels-right">
  284. <span class="mlabels"><span class="mlabel">related</span></span> </td>
  285. </tr>
  286. </table>
  287. </div><div class="memdoc">
  288. <p><code>#include &lt;<a class="el" href="fwd_2keys_8hpp.html">boost/hana/fwd/keys.hpp</a>&gt;</code></p>
  289. <p>Returns a <code>Sequence</code> containing the name of the members of the data structure.Given a <code>Struct</code> object, <code>keys</code> returns a <code>Sequence</code> containing the name of all the members of the <code>Struct</code>, in the same order as they appear in the <code>accessors</code> sequence. </p>
  290. <h2>Example </h2>
  291. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="keys_8hpp.html">boost/hana/keys.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="string_8hpp.html">boost/hana/string.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> <a class="code" href="group__group-Struct.html#gaf8c7199742581e6e66c8397def68e2d3">hana::keys</a>(john) == hana::make_tuple(BOOST_HANA_STRING(<span class="stringliteral">&quot;name&quot;</span>),</div><div class="line"> BOOST_HANA_STRING(<span class="stringliteral">&quot;age&quot;</span>))</div><div class="line"> );</div><div class="line">}</div></div><!-- fragment -->
  292. </div>
  293. </div>
  294. <a id="gad301dd8e9fb4639d7874619c97d6d427"></a>
  295. <h2 class="memtitle"><span class="permalink"><a href="#gad301dd8e9fb4639d7874619c97d6d427">&#9670;&nbsp;</a></span>members</h2>
  296. <div class="memitem">
  297. <div class="memproto">
  298. <table class="memname">
  299. <tr>
  300. <td class="memname">constexpr auto boost::hana::members</td>
  301. </tr>
  302. </table>
  303. </div><div class="memdoc">
  304. <p><code>#include &lt;<a class="el" href="fwd_2members_8hpp.html">boost/hana/fwd/members.hpp</a>&gt;</code></p>
  305. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; object) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  306. <p>Returns a <code>Sequence</code> containing the members of a <code>Struct</code>.Given a <code>Struct</code> object, <code>members</code> returns a <code>Sequence</code> containing all the members of the <code>Struct</code>, in the same order as their respective accessor appears in the <code>accessors</code> sequence. </p>
  307. <h2>Example </h2>
  308. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="define__struct_8hpp.html">boost/hana/define_struct.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="members_8hpp.html">boost/hana/members.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>Person {</div><div class="line"> <a class="code" href="group__group-Struct.html#gab9efb238a82207d91643994c5295cf8c">BOOST_HANA_DEFINE_STRUCT</a>(Person,</div><div class="line"> (std::string, name),</div><div class="line"> (<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span>, age)</div><div class="line"> );</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> Person john{<span class="stringliteral">&quot;John&quot;</span>, 30};</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Struct.html#gad301dd8e9fb4639d7874619c97d6d427">hana::members</a>(john) == hana::make_tuple(<span class="stringliteral">&quot;John&quot;</span>, 30));</div><div class="line">}</div></div><!-- fragment -->
  309. </div>
  310. </div>
  311. </div><!-- contents -->
  312. </div><!-- doc-content -->
  313. <!--
  314. Copyright Louis Dionne 2013-2017
  315. Distributed under the Boost Software License, Version 1.0.
  316. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  317. -->
  318. <!-- boost-no-inspect -->
  319. <!-- HTML footer for doxygen 1.8.9.1-->
  320. <!-- start footer part -->
  321. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  322. <ul>
  323. </ul>
  324. </div>
  325. </body>
  326. </html>