group__group-Metafunction.html 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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: Metafunction</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-Metafunction.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="#var-members">Variables</a> </div>
  130. <div class="headertitle">
  131. <div class="title">Metafunction<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>A <code>Metafunction</code> is a function that takes <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code>s as inputs and returns a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> as output. </p>
  136. <p>A <code>Metafunction</code> is an object satisfying the <a href="http://en.cppreference.com/w/cpp/named_req/FunctionObject">FunctionObject</a> concept, but with additional requirements. First, it must be possible to apply a <code>Metafunction</code> to arguments whose tag is <code><a class="el" href="structboost_1_1hana_1_1type__tag.html" title="Tag representing hana::type.">type_tag</a></code>, and the result of such an application must be an object whose tag is also <code><a class="el" href="structboost_1_1hana_1_1type__tag.html" title="Tag representing hana::type.">type_tag</a></code>. Note that <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> and <code><a class="el" href="structboost_1_1hana_1_1basic__type.html" title="Base class of hana::type; used for pattern-matching.">hana::basic_type</a></code> are the only such types.</p>
  137. <p>Secondly, a <code>Metafunction</code> must provide a nested <code>::apply</code> template which allows performing the same type-level computation as is done by the call operator. In Boost.MPL parlance, a <code>Metafunction</code> <code>F</code> is hence a <a href="http://www.boost.org/doc/libs/release/libs/mpl/doc/refmanual/metafunction-class.html">MetafunctionClass</a> in addition to being a <code>FunctionObject</code>. Rigorously, the following must be satisfied by any object <code>f</code> of type <code>F</code> which is a <code>Metafunction</code>, and for arbitrary types <code>T...</code>: </p><div class="fragment"><div class="line">f(hana::type_c&lt;T&gt;...) == hana::type_c&lt;<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">F::apply</a>&lt;T...&gt;::type&gt;</div></div><!-- fragment --><p>Thirdly, to ease the inter-operation of values and types, <code>Metafunction</code>s must also allow being called with arguments that are not <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code>s. In that case, the result is equivalent to calling the metafunction on the types of the arguments. Rigorously, this means that for arbitrary objects <code>x...</code>, </p><div class="fragment"><div class="line">f(x...) == f(hana::type_c&lt;decltype(x)&gt;...)</div></div><!-- fragment --><h2>Minimal complete definition </h2>
  138. <p>The <code>Metafunction</code> concept does not have a minimal complete definition in terms of tag-dispatched methods. Instead, the syntactic requirements documented above should be satisfied, and the <code>Metafunction</code> struct should be specialized explicitly in Hana's namespace.</p>
  139. <h2>Concrete models </h2>
  140. <p><code><a class="el" href="group__group-Metafunction.html#gaaa4f85cb8cbce21f5c04ef40ca35cc6a" title="Lift a MPL-style metafunction to a Metafunction.Given a MPL-style metafunction, metafunction&lt;f&gt; is a ...">hana::metafunction</a></code>, <code><a class="el" href="group__group-Metafunction.html#gacec153d7f86aa7cf1efd813b3fd212b4" title="Lift a MPL-style metafunction class to a Metafunction.Given a MPL-style metafunction class,...">hana::metafunction_class</a></code>, <code><a class="el" href="group__group-Metafunction.html#ga246419f6c3263b648412f346106e6543" title="Lift a template to a Metafunction.Given a template class or template alias f, template_&lt;f&gt; is a Metaf...">hana::template_</a></code></p>
  141. <h2>Rationale: Why aren't <code>Metafunction</code>s <code>Comparable</code>? </h2>
  142. <p>When seeing <code><a class="el" href="group__group-Metafunction.html#ga246419f6c3263b648412f346106e6543" title="Lift a template to a Metafunction.Given a template class or template alias f, template_&lt;f&gt; is a Metaf...">hana::template_</a></code>, a question that naturally arises is whether <code>Metafunction</code>s should be made <code>Comparable</code>. Indeed, it would seem to make sense to compare two templates <code>F</code> and <code>G</code> with <code>template_&lt;F&gt; == template_&lt;G&gt;</code>. However, in the case where <code>F</code> and/or <code>G</code> are alias templates, it makes sense to talk about two types of comparisons. The first one is <em>shallow</em> comparison, and it determines that two alias templates are equal if they are the same alias template. The second one is <em>deep</em> comparison, and it determines that two template aliases are equal if they alias the same type for any template argument. For example, given <code>F</code> and <code>G</code> defined as </p><div class="fragment"><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><span class="keyword">using</span> F = void;</div><div class="line"></div><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><span class="keyword">using</span> G = void;</div></div><!-- fragment --><p>shallow comparison would determine that <code>F</code> and <code>G</code> are different because they are two different template aliases, while deep comparison would determine that <code>F</code> and <code>G</code> are equal because they always expand to the same type, <code>void</code>. Unfortunately, deep comparison is impossible to implement because one would have to check <code>F</code> and <code>G</code> on all possible types. On the other hand, shallow comparison is not satisfactory because <code>Metafunction</code>s are nothing but functions on <code>type</code>s, and the equality of two functions is normally defined with deep comparison. Hence, we adopt a conservative stance and avoid providing comparison for <code>Metafunction</code>s. </p>
  143. <table class="memberdecls">
  144. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  145. Variables</h2></td></tr>
  146. <tr class="memitem:ga246419f6c3263b648412f346106e6543"><td class="memTemplParams" colspan="2">template&lt;template&lt; typename ... &gt; class F&gt; </td></tr>
  147. <tr class="memitem:ga246419f6c3263b648412f346106e6543"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Metafunction.html#ga246419f6c3263b648412f346106e6543">boost::hana::template_</a></td></tr>
  148. <tr class="memdesc:ga246419f6c3263b648412f346106e6543"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lift a template to a Metafunction.Given a template class or template alias <code>f</code>, <code>template_&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. <a href="group__group-Metafunction.html#ga246419f6c3263b648412f346106e6543">More...</a><br /></td></tr>
  149. <tr class="separator:ga246419f6c3263b648412f346106e6543"><td class="memSeparator" colspan="2">&#160;</td></tr>
  150. <tr class="memitem:gaaa4f85cb8cbce21f5c04ef40ca35cc6a"><td class="memTemplParams" colspan="2">template&lt;template&lt; typename ... &gt; class F&gt; </td></tr>
  151. <tr class="memitem:gaaa4f85cb8cbce21f5c04ef40ca35cc6a"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Metafunction.html#gaaa4f85cb8cbce21f5c04ef40ca35cc6a">boost::hana::metafunction</a></td></tr>
  152. <tr class="memdesc:gaaa4f85cb8cbce21f5c04ef40ca35cc6a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lift a MPL-style metafunction to a Metafunction.Given a MPL-style metafunction, <code>metafunction&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. <a href="group__group-Metafunction.html#gaaa4f85cb8cbce21f5c04ef40ca35cc6a">More...</a><br /></td></tr>
  153. <tr class="separator:gaaa4f85cb8cbce21f5c04ef40ca35cc6a"><td class="memSeparator" colspan="2">&#160;</td></tr>
  154. <tr class="memitem:gacec153d7f86aa7cf1efd813b3fd212b4"><td class="memTemplParams" colspan="2">template&lt;typename F &gt; </td></tr>
  155. <tr class="memitem:gacec153d7f86aa7cf1efd813b3fd212b4"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Metafunction.html#gacec153d7f86aa7cf1efd813b3fd212b4">boost::hana::metafunction_class</a></td></tr>
  156. <tr class="memdesc:gacec153d7f86aa7cf1efd813b3fd212b4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lift a MPL-style metafunction class to a Metafunction.Given a MPL-style metafunction class, <code>metafunction_class&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. <a href="group__group-Metafunction.html#gacec153d7f86aa7cf1efd813b3fd212b4">More...</a><br /></td></tr>
  157. <tr class="separator:gacec153d7f86aa7cf1efd813b3fd212b4"><td class="memSeparator" colspan="2">&#160;</td></tr>
  158. <tr class="memitem:gaf7045fe6a627f88f5f646dad22d37aae"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">boost::hana::integral</a></td></tr>
  159. <tr class="memdesc:gaf7045fe6a627f88f5f646dad22d37aae"><td class="mdescLeft">&#160;</td><td class="mdescRight">Turn a <code>Metafunction</code> into a function taking <code>type</code>s and returning a default-constructed object.Given a <code>Metafunction</code> <code>f</code>, <code>integral</code> returns a new <code>Metafunction</code> that default-constructs an object of the type returned by <code>f</code>. More specifically, the following holds: <a href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">More...</a><br /></td></tr>
  160. <tr class="separator:gaf7045fe6a627f88f5f646dad22d37aae"><td class="memSeparator" colspan="2">&#160;</td></tr>
  161. <tr class="memitem:ga6d4093318f46472e62f9539a4dc998a9"><td class="memTemplParams" colspan="2">template&lt;template&lt; typename ... &gt; class F&gt; </td></tr>
  162. <tr class="memitem:ga6d4093318f46472e62f9539a4dc998a9"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-Metafunction.html#ga6d4093318f46472e62f9539a4dc998a9">boost::hana::trait</a> = <a class="el" href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">hana::integral</a>(<a class="el" href="group__group-Metafunction.html#gaaa4f85cb8cbce21f5c04ef40ca35cc6a">hana::metafunction</a>&lt;F&gt;)</td></tr>
  163. <tr class="memdesc:ga6d4093318f46472e62f9539a4dc998a9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Alias to <code>integral(metafunction&lt;F&gt;)</code>, provided for convenience. <a href="group__group-Metafunction.html#ga6d4093318f46472e62f9539a4dc998a9">More...</a><br /></td></tr>
  164. <tr class="separator:ga6d4093318f46472e62f9539a4dc998a9"><td class="memSeparator" colspan="2">&#160;</td></tr>
  165. </table>
  166. <h2 class="groupheader">Variable Documentation</h2>
  167. <a id="ga246419f6c3263b648412f346106e6543"></a>
  168. <h2 class="memtitle"><span class="permalink"><a href="#ga246419f6c3263b648412f346106e6543">&#9670;&nbsp;</a></span>template_</h2>
  169. <div class="memitem">
  170. <div class="memproto">
  171. <div class="memtemplate">
  172. template&lt;template&lt; typename ... &gt; class F&gt; </div>
  173. <table class="memname">
  174. <tr>
  175. <td class="memname">constexpr auto boost::hana::template_</td>
  176. </tr>
  177. </table>
  178. </div><div class="memdoc">
  179. <p><code>#include &lt;<a class="el" href="fwd_2type_8hpp.html">boost/hana/fwd/type.hpp</a>&gt;</code></p>
  180. <b>Initial value:</b><div class="fragment"><div class="line">= [](basic_type&lt;T&gt;...) {</div><div class="line"> <span class="keywordflow">return</span> hana::type_c&lt;F&lt;T...&gt;&gt;;</div><div class="line"> }</div></div><!-- fragment -->
  181. <p>Lift a template to a Metafunction.Given a template class or template alias <code>f</code>, <code>template_&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. </p>
  182. <div class="fragment"><div class="line">template_&lt;f&gt;(type_c&lt;x&gt;...) == type_c&lt;f&lt;x...&gt;&gt;</div><div class="line">decltype(template_&lt;f&gt;)::<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;x...&gt;::type == f&lt;x...&gt;</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>In a SFINAE context, the expression <code>template_&lt;f&gt;(type_c&lt;x&gt;...)</code> is valid whenever the expression <code>f&lt;x...&gt;</code> is valid.</dd></dl>
  183. <h2>Example </h2>
  184. <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="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&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">template</span> &lt;<span class="keyword">typename</span> ...&gt; <span class="keyword">struct </span>f;</div><div class="line"><span class="keyword">struct </span>x;</div><div class="line"><span class="keyword">struct </span>y;</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::template_&lt;f&gt;() == hana::type_c&lt;f&lt;&gt;&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::template_&lt;f&gt;(hana::type_c&lt;x&gt;) == hana::type_c&lt;f&lt;x&gt;&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::template_&lt;f&gt;(hana::type_c&lt;x&gt;, hana::type_c&lt;y&gt;) == hana::type_c&lt;f&lt;x, y&gt;&gt;);</div><div class="line"></div><div class="line">static_assert(std::is_same&lt;</div><div class="line"> decltype(hana::template_&lt;f&gt;)::apply&lt;x, y&gt;::type,</div><div class="line"> f&lt;x, y&gt;</div><div class="line">&gt;::<a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  185. </div>
  186. </div>
  187. <a id="gaaa4f85cb8cbce21f5c04ef40ca35cc6a"></a>
  188. <h2 class="memtitle"><span class="permalink"><a href="#gaaa4f85cb8cbce21f5c04ef40ca35cc6a">&#9670;&nbsp;</a></span>metafunction</h2>
  189. <div class="memitem">
  190. <div class="memproto">
  191. <div class="memtemplate">
  192. template&lt;template&lt; typename ... &gt; class F&gt; </div>
  193. <table class="memname">
  194. <tr>
  195. <td class="memname">constexpr auto boost::hana::metafunction</td>
  196. </tr>
  197. </table>
  198. </div><div class="memdoc">
  199. <p><code>#include &lt;<a class="el" href="fwd_2type_8hpp.html">boost/hana/fwd/type.hpp</a>&gt;</code></p>
  200. <b>Initial value:</b><div class="fragment"><div class="line">= [](basic_type&lt;T&gt;...) {</div><div class="line"> <span class="keywordflow">return</span> hana::type_c&lt;<span class="keyword">typename</span> F&lt;T...&gt;::type&gt;;</div><div class="line"> }</div></div><!-- fragment -->
  201. <p>Lift a MPL-style metafunction to a Metafunction.Given a MPL-style metafunction, <code>metafunction&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. </p>
  202. <div class="fragment"><div class="line">metafunction&lt;f&gt;(type_c&lt;x&gt;...) == type_c&lt;f&lt;x...&gt;::type&gt;</div><div class="line">decltype(metafunction&lt;f&gt;)::<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;x...&gt;::type == f&lt;x...&gt;::type</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>In a SFINAE context, the expression <code>metafunction&lt;f&gt;(type_c&lt;x&gt;...)</code> is valid whenever the expression <code>f&lt;x...&gt;::type</code> is valid.</dd></dl>
  203. <h2>Example </h2>
  204. <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="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&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">template</span> &lt;<span class="keyword">typename</span> ...&gt; <span class="keyword">struct </span>f { <span class="keyword">struct </span>type; };</div><div class="line"><span class="keyword">struct </span>x;</div><div class="line"><span class="keyword">struct </span>y;</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction&lt;f&gt;() == hana::type_c&lt;f&lt;&gt;::type&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction&lt;f&gt;(hana::type_c&lt;x&gt;) == hana::type_c&lt;f&lt;x&gt;::type&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction&lt;f&gt;(hana::type_c&lt;x&gt;, hana::type_c&lt;y&gt;) == hana::type_c&lt;f&lt;x, y&gt;::type&gt;);</div><div class="line"></div><div class="line">static_assert(std::is_same&lt;</div><div class="line"> decltype(hana::metafunction&lt;f&gt;)::apply&lt;x, y&gt;::type,</div><div class="line"> f&lt;x, y&gt;::type</div><div class="line">&gt;::<a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  205. </div>
  206. </div>
  207. <a id="gacec153d7f86aa7cf1efd813b3fd212b4"></a>
  208. <h2 class="memtitle"><span class="permalink"><a href="#gacec153d7f86aa7cf1efd813b3fd212b4">&#9670;&nbsp;</a></span>metafunction_class</h2>
  209. <div class="memitem">
  210. <div class="memproto">
  211. <div class="memtemplate">
  212. template&lt;typename F &gt; </div>
  213. <table class="memname">
  214. <tr>
  215. <td class="memname">constexpr auto boost::hana::metafunction_class</td>
  216. </tr>
  217. </table>
  218. </div><div class="memdoc">
  219. <p><code>#include &lt;<a class="el" href="fwd_2type_8hpp.html">boost/hana/fwd/type.hpp</a>&gt;</code></p>
  220. <b>Initial value:</b><div class="fragment"><div class="line">= [](basic_type&lt;T&gt;...) {</div><div class="line"> <span class="keywordflow">return</span> hana::type_c&lt;<span class="keyword">typename</span> F::template <a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;T...&gt;::type&gt;;</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga30027c383676084be151ef3c6cf2829f"><div class="ttname"><a href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">boost::hana::apply</a></div><div class="ttdeci">constexpr auto apply</div><div class="ttdoc">Invokes a Callable with the given arguments.</div><div class="ttdef"><b>Definition:</b> apply.hpp:40</div></div>
  221. </div><!-- fragment -->
  222. <p>Lift a MPL-style metafunction class to a Metafunction.Given a MPL-style metafunction class, <code>metafunction_class&lt;f&gt;</code> is a <code>Metafunction</code> satisfying. </p>
  223. <div class="fragment"><div class="line">metafunction_class&lt;f&gt;(type_c&lt;x&gt;...) == type_c&lt;<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">f::apply</a>&lt;x...&gt;::type&gt;</div><div class="line">decltype(metafunction_class&lt;f&gt;)::<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;x...&gt;::type == f::<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;x...&gt;::type</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>In a SFINAE context, the expression <code>metafunction_class&lt;f&gt;(type_c&lt;x&gt;...)</code> is valid whenever the expression <code>f::apply&lt;x...&gt;::type</code> is valid.</dd></dl>
  224. <h2>Example </h2>
  225. <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="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&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>f { <span class="keyword">template</span> &lt;<span class="keyword">typename</span> ...&gt; <span class="keyword">struct </span><a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a> { <span class="keyword">struct </span>type; }; };</div><div class="line"><span class="keyword">struct </span>x;</div><div class="line"><span class="keyword">struct </span>y;</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction_class&lt;f&gt;() == hana::type_c&lt;f::apply&lt;&gt;::type&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction_class&lt;f&gt;(hana::type_c&lt;x&gt;) == hana::type_c&lt;f::apply&lt;x&gt;::type&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::metafunction_class&lt;f&gt;(hana::type_c&lt;x&gt;, hana::type_c&lt;y&gt;) == hana::type_c&lt;f::apply&lt;x, y&gt;::type&gt;);</div><div class="line"></div><div class="line">static_assert(std::is_same&lt;</div><div class="line"> decltype(hana::metafunction_class&lt;f&gt;)::apply&lt;x, y&gt;::type,</div><div class="line"> f::apply&lt;x, y&gt;::type</div><div class="line">&gt;::<a class="code" href="group__group-Constant.html#ga1687520692a6b0c49e3a69de2980f388">value</a>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  226. </div>
  227. </div>
  228. <a id="gaf7045fe6a627f88f5f646dad22d37aae"></a>
  229. <h2 class="memtitle"><span class="permalink"><a href="#gaf7045fe6a627f88f5f646dad22d37aae">&#9670;&nbsp;</a></span>integral</h2>
  230. <div class="memitem">
  231. <div class="memproto">
  232. <table class="memname">
  233. <tr>
  234. <td class="memname">constexpr auto boost::hana::integral</td>
  235. </tr>
  236. </table>
  237. </div><div class="memdoc">
  238. <p><code>#include &lt;<a class="el" href="fwd_2type_8hpp.html">boost/hana/fwd/type.hpp</a>&gt;</code></p>
  239. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span> f) {</div><div class="line"> <span class="keywordflow">return</span> [](basic_type&lt;T&gt;...) {</div><div class="line"> <span class="keywordflow">return</span> decltype(f)::<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">apply</a>&lt;T...&gt;::type{};</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga30027c383676084be151ef3c6cf2829f"><div class="ttname"><a href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">boost::hana::apply</a></div><div class="ttdeci">constexpr auto apply</div><div class="ttdoc">Invokes a Callable with the given arguments.</div><div class="ttdef"><b>Definition:</b> apply.hpp:40</div></div>
  240. </div><!-- fragment -->
  241. <p>Turn a <code>Metafunction</code> into a function taking <code>type</code>s and returning a default-constructed object.Given a <code>Metafunction</code> <code>f</code>, <code>integral</code> returns a new <code>Metafunction</code> that default-constructs an object of the type returned by <code>f</code>. More specifically, the following holds: </p>
  242. <div class="fragment"><div class="line"><a class="code" href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">integral</a>(f)(t...) == decltype(f(t...))::type{}</div></div><!-- fragment --><p>The principal use case for <code>integral</code> is to transform <code>Metafunction</code>s returning a type that inherits from a meaningful base like <code><a class="el" href="structstd_1_1integral__constant.html" title="Adapter for std::integral_constants.">std::integral_constant</a></code> into functions returning e.g. a <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>.</p>
  243. <dl class="section note"><dt>Note</dt><dd><ul>
  244. <li>This is not a <code>Metafunction</code> because it does not return a <code>type</code>. As such, it would not make sense to make <code>decltype(integral(f))</code> a MPL metafunction class like the usual <code>Metafunction</code>s are.</li>
  245. <li>When using <code>integral</code> with metafunctions returning <code><a class="el" href="structstd_1_1integral__constant.html" title="Adapter for std::integral_constants.">std::integral_constant</a></code>s, don't forget to include the <a class="el" href="ext_2std_2integral__constant_8hpp.html" title="Adapts std::integral_constant for use with Hana.">boost/hana/ext/std/integral_constant.hpp</a> header to ensure Hana can interoperate with the result.</li>
  246. <li>In a SFINAE context, the expression <code>integral(f)(t...)</code> is valid whenever the expression <code>decltype(f(t...))::type</code> is valid.</li>
  247. </ul>
  248. </dd></dl>
  249. <h2>Example </h2>
  250. <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="ext_2std_2integral__constant_8hpp.html">boost/hana/ext/std/integral_constant.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not_8hpp.html">boost/hana/not.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&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">constexpr <span class="keyword">auto</span> is_void = <a class="code" href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">hana::integral</a>(hana::metafunction&lt;std::is_void&gt;);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(is_void(hana::type_c&lt;void&gt;));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Logical.html#ga4a7c9d7037601d5e553fd20777958980">hana::not_</a>(is_void(hana::type_c&lt;int&gt;)));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  251. </div>
  252. </div>
  253. <a id="ga6d4093318f46472e62f9539a4dc998a9"></a>
  254. <h2 class="memtitle"><span class="permalink"><a href="#ga6d4093318f46472e62f9539a4dc998a9">&#9670;&nbsp;</a></span>trait</h2>
  255. <div class="memitem">
  256. <div class="memproto">
  257. <div class="memtemplate">
  258. template&lt;template&lt; typename ... &gt; class F&gt; </div>
  259. <table class="memname">
  260. <tr>
  261. <td class="memname">constexpr auto boost::hana::trait = <a class="el" href="group__group-Metafunction.html#gaf7045fe6a627f88f5f646dad22d37aae">hana::integral</a>(<a class="el" href="group__group-Metafunction.html#gaaa4f85cb8cbce21f5c04ef40ca35cc6a">hana::metafunction</a>&lt;F&gt;)</td>
  262. </tr>
  263. </table>
  264. </div><div class="memdoc">
  265. <p><code>#include &lt;<a class="el" href="fwd_2type_8hpp.html">boost/hana/fwd/type.hpp</a>&gt;</code></p>
  266. <p>Alias to <code>integral(metafunction&lt;F&gt;)</code>, provided for convenience. </p>
  267. <h2>Example </h2>
  268. <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="ext_2std_2integral__constant_8hpp.html">boost/hana/ext/std/integral_constant.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not_8hpp.html">boost/hana/not.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&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"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::trait&lt;std::is_integral&gt;(hana::type_c&lt;int&gt;));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Logical.html#ga4a7c9d7037601d5e553fd20777958980">hana::not_</a>(hana::trait&lt;std::is_integral&gt;(hana::type_c&lt;float&gt;)));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  269. </div>
  270. </div>
  271. </div><!-- contents -->
  272. </div><!-- doc-content -->
  273. <!--
  274. Copyright Louis Dionne 2013-2017
  275. Distributed under the Boost Software License, Version 1.0.
  276. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  277. -->
  278. <!-- boost-no-inspect -->
  279. <!-- HTML footer for doxygen 1.8.9.1-->
  280. <!-- start footer part -->
  281. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  282. <ul>
  283. </ul>
  284. </div>
  285. </body>
  286. </html>