group__group-functional.html 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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: Functional</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-functional.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">Functional</div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>General purpose function objects. </p>
  136. <table class="memberdecls">
  137. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  138. Variables</h2></td></tr>
  139. <tr class="memitem:ga835970cb25a0c8dc200f1e5f8943538b"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga835970cb25a0c8dc200f1e5f8943538b">boost::hana::always</a></td></tr>
  140. <tr class="memdesc:ga835970cb25a0c8dc200f1e5f8943538b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return a constant function returning <code>x</code> regardless of the argument(s) it is invoked with. <a href="group__group-functional.html#ga835970cb25a0c8dc200f1e5f8943538b">More...</a><br /></td></tr>
  141. <tr class="separator:ga835970cb25a0c8dc200f1e5f8943538b"><td class="memSeparator" colspan="2">&#160;</td></tr>
  142. <tr class="memitem:ga30027c383676084be151ef3c6cf2829f"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">boost::hana::apply</a></td></tr>
  143. <tr class="memdesc:ga30027c383676084be151ef3c6cf2829f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Invokes a Callable with the given arguments. <a href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">More...</a><br /></td></tr>
  144. <tr class="separator:ga30027c383676084be151ef3c6cf2829f"><td class="memSeparator" colspan="2">&#160;</td></tr>
  145. <tr class="memitem:ga6acc765a35c4dc85f0deab4785831a3d"><td class="memTemplParams" colspan="2">template&lt;std::size_t n&gt; </td></tr>
  146. <tr class="memitem:ga6acc765a35c4dc85f0deab4785831a3d"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga6acc765a35c4dc85f0deab4785831a3d">boost::hana::arg</a></td></tr>
  147. <tr class="memdesc:ga6acc765a35c4dc85f0deab4785831a3d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the <code>n</code>th passed argument. <a href="group__group-functional.html#ga6acc765a35c4dc85f0deab4785831a3d">More...</a><br /></td></tr>
  148. <tr class="separator:ga6acc765a35c4dc85f0deab4785831a3d"><td class="memSeparator" colspan="2">&#160;</td></tr>
  149. <tr class="memitem:ga41ada6b336e9d5bcb101ff0c737acbd0"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></td></tr>
  150. <tr class="memdesc:ga41ada6b336e9d5bcb101ff0c737acbd0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a function capturing the given variables. <a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">More...</a><br /></td></tr>
  151. <tr class="separator:ga41ada6b336e9d5bcb101ff0c737acbd0"><td class="memSeparator" colspan="2">&#160;</td></tr>
  152. <tr class="memitem:ga3b16146e53efcdf9ecbb9a7b21f8cd0b"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">boost::hana::compose</a></td></tr>
  153. <tr class="memdesc:ga3b16146e53efcdf9ecbb9a7b21f8cd0b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the composition of two functions or more. <a href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">More...</a><br /></td></tr>
  154. <tr class="separator:ga3b16146e53efcdf9ecbb9a7b21f8cd0b"><td class="memSeparator" colspan="2">&#160;</td></tr>
  155. <tr class="memitem:ga49ea872ade5ac8f6c10052c495302e89"><td class="memTemplParams" colspan="2">template&lt;std::size_t n&gt; </td></tr>
  156. <tr class="memitem:ga49ea872ade5ac8f6c10052c495302e89"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga49ea872ade5ac8f6c10052c495302e89">boost::hana::curry</a></td></tr>
  157. <tr class="memdesc:ga49ea872ade5ac8f6c10052c495302e89"><td class="mdescLeft">&#160;</td><td class="mdescRight">Curry a function up to the given number of arguments. <a href="group__group-functional.html#ga49ea872ade5ac8f6c10052c495302e89">More...</a><br /></td></tr>
  158. <tr class="separator:ga49ea872ade5ac8f6c10052c495302e89"><td class="memSeparator" colspan="2">&#160;</td></tr>
  159. <tr class="memitem:ga3a8316acd5efa22c3d1861b62d5df3c2"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">boost::hana::demux</a></td></tr>
  160. <tr class="memdesc:ga3a8316acd5efa22c3d1861b62d5df3c2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Invoke a function with the results of invoking other functions on its arguments. <a href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">More...</a><br /></td></tr>
  161. <tr class="separator:ga3a8316acd5efa22c3d1861b62d5df3c2"><td class="memSeparator" colspan="2">&#160;</td></tr>
  162. <tr class="memitem:ga1393f40da2e8da6e0c12fce953e56a6c"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">boost::hana::fix</a></td></tr>
  163. <tr class="memdesc:ga1393f40da2e8da6e0c12fce953e56a6c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return a function computing the fixed point of a function. <a href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">More...</a><br /></td></tr>
  164. <tr class="separator:ga1393f40da2e8da6e0c12fce953e56a6c"><td class="memSeparator" colspan="2">&#160;</td></tr>
  165. <tr class="memitem:ga004f884cdbb85c2efe3383c1db450094"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga004f884cdbb85c2efe3383c1db450094">boost::hana::flip</a></td></tr>
  166. <tr class="memdesc:ga004f884cdbb85c2efe3383c1db450094"><td class="mdescLeft">&#160;</td><td class="mdescRight">Invoke a function with its two first arguments reversed. <a href="group__group-functional.html#ga004f884cdbb85c2efe3383c1db450094">More...</a><br /></td></tr>
  167. <tr class="separator:ga004f884cdbb85c2efe3383c1db450094"><td class="memSeparator" colspan="2">&#160;</td></tr>
  168. <tr class="memitem:gaef38cf34324c8edbd3597ae71811d00d"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">boost::hana::id</a></td></tr>
  169. <tr class="memdesc:gaef38cf34324c8edbd3597ae71811d00d"><td class="mdescLeft">&#160;</td><td class="mdescRight">The identity function &ndash; returns its argument unchanged. <a href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">More...</a><br /></td></tr>
  170. <tr class="separator:gaef38cf34324c8edbd3597ae71811d00d"><td class="memSeparator" colspan="2">&#160;</td></tr>
  171. <tr class="memitem:ga7bdafba6dc801f1d2d83731ad9714557"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">boost::hana::infix</a></td></tr>
  172. <tr class="memdesc:ga7bdafba6dc801f1d2d83731ad9714557"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return an equivalent function that can also be applied in infix notation. <a href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">More...</a><br /></td></tr>
  173. <tr class="separator:ga7bdafba6dc801f1d2d83731ad9714557"><td class="memSeparator" colspan="2">&#160;</td></tr>
  174. <tr class="memitem:gad1b8669c022d8675d68e5974451073d1"><td class="memTemplParams" colspan="2">template&lt;std::size_t n&gt; </td></tr>
  175. <tr class="memitem:gad1b8669c022d8675d68e5974451073d1"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="group__group-functional.html#gad1b8669c022d8675d68e5974451073d1">boost::hana::iterate</a></td></tr>
  176. <tr class="memdesc:gad1b8669c022d8675d68e5974451073d1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Applies another function <code>n</code> times to its argument. <a href="group__group-functional.html#gad1b8669c022d8675d68e5974451073d1">More...</a><br /></td></tr>
  177. <tr class="separator:gad1b8669c022d8675d68e5974451073d1"><td class="memSeparator" colspan="2">&#160;</td></tr>
  178. <tr class="memitem:gafca60c09e1f7a32a2b52baaf6515c279"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#gafca60c09e1f7a32a2b52baaf6515c279">boost::hana::lockstep</a></td></tr>
  179. <tr class="memdesc:gafca60c09e1f7a32a2b52baaf6515c279"><td class="mdescLeft">&#160;</td><td class="mdescRight">Invoke a function with the result of invoking other functions on its arguments, in lockstep. <a href="group__group-functional.html#gafca60c09e1f7a32a2b52baaf6515c279">More...</a><br /></td></tr>
  180. <tr class="separator:gafca60c09e1f7a32a2b52baaf6515c279"><td class="memSeparator" colspan="2">&#160;</td></tr>
  181. <tr class="memitem:ga35c4fc3c5677b9f558150b90e74d3ab1"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">boost::hana::on</a></td></tr>
  182. <tr class="memdesc:ga35c4fc3c5677b9f558150b90e74d3ab1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Invoke a function with the result of invoking another function on each argument. <a href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">More...</a><br /></td></tr>
  183. <tr class="separator:ga35c4fc3c5677b9f558150b90e74d3ab1"><td class="memSeparator" colspan="2">&#160;</td></tr>
  184. <tr class="memitem:ga83e71bae315e299f9f5f9de77b012139"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga83e71bae315e299f9f5f9de77b012139">boost::hana::overload</a></td></tr>
  185. <tr class="memdesc:ga83e71bae315e299f9f5f9de77b012139"><td class="mdescLeft">&#160;</td><td class="mdescRight">Pick one of several functions to call based on overload resolution. <a href="group__group-functional.html#ga83e71bae315e299f9f5f9de77b012139">More...</a><br /></td></tr>
  186. <tr class="separator:ga83e71bae315e299f9f5f9de77b012139"><td class="memSeparator" colspan="2">&#160;</td></tr>
  187. <tr class="memitem:gaa46de6f618d9f14edb1589b36b6e75ec"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#gaa46de6f618d9f14edb1589b36b6e75ec">boost::hana::overload_linearly</a></td></tr>
  188. <tr class="memdesc:gaa46de6f618d9f14edb1589b36b6e75ec"><td class="mdescLeft">&#160;</td><td class="mdescRight">Call the first function that produces a valid call expression. <a href="group__group-functional.html#gaa46de6f618d9f14edb1589b36b6e75ec">More...</a><br /></td></tr>
  189. <tr class="separator:gaa46de6f618d9f14edb1589b36b6e75ec"><td class="memSeparator" colspan="2">&#160;</td></tr>
  190. <tr class="memitem:ga778b2daa27882e71d28b6f2b38982ddf"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga778b2daa27882e71d28b6f2b38982ddf">boost::hana::partial</a></td></tr>
  191. <tr class="memdesc:ga778b2daa27882e71d28b6f2b38982ddf"><td class="mdescLeft">&#160;</td><td class="mdescRight">Partially apply a function to some arguments. <a href="group__group-functional.html#ga778b2daa27882e71d28b6f2b38982ddf">More...</a><br /></td></tr>
  192. <tr class="separator:ga778b2daa27882e71d28b6f2b38982ddf"><td class="memSeparator" colspan="2">&#160;</td></tr>
  193. <tr class="memitem:gaefe9fd152cba94be71c2b5b9de689d23"><td class="memItemLeft" align="right" valign="top">constexpr unspecified&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">boost::hana::_</a> {}</td></tr>
  194. <tr class="memdesc:gaefe9fd152cba94be71c2b5b9de689d23"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create simple functions representing C++ operators inline. <a href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">More...</a><br /></td></tr>
  195. <tr class="separator:gaefe9fd152cba94be71c2b5b9de689d23"><td class="memSeparator" colspan="2">&#160;</td></tr>
  196. <tr class="memitem:ga6e648f0d3fc0209ec024e9d759a5e8f8"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-functional.html#ga6e648f0d3fc0209ec024e9d759a5e8f8">boost::hana::reverse_partial</a></td></tr>
  197. <tr class="memdesc:ga6e648f0d3fc0209ec024e9d759a5e8f8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Partially apply a function to some arguments. <a href="group__group-functional.html#ga6e648f0d3fc0209ec024e9d759a5e8f8">More...</a><br /></td></tr>
  198. <tr class="separator:ga6e648f0d3fc0209ec024e9d759a5e8f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
  199. </table>
  200. <h2 class="groupheader">Variable Documentation</h2>
  201. <a id="ga835970cb25a0c8dc200f1e5f8943538b"></a>
  202. <h2 class="memtitle"><span class="permalink"><a href="#ga835970cb25a0c8dc200f1e5f8943538b">&#9670;&nbsp;</a></span>always</h2>
  203. <div class="memitem">
  204. <div class="memproto">
  205. <table class="memname">
  206. <tr>
  207. <td class="memname">constexpr auto boost::hana::always</td>
  208. </tr>
  209. </table>
  210. </div><div class="memdoc">
  211. <p><code>#include &lt;<a class="el" href="always_8hpp.html">boost/hana/functional/always.hpp</a>&gt;</code></p>
  212. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span> <span class="keyword">const</span>&amp; ...y) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(x);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  213. </div><!-- fragment -->
  214. <p>Return a constant function returning <code>x</code> regardless of the argument(s) it is invoked with. </p>
  215. <p>Specifically, <code>always(x)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga835970cb25a0c8dc200f1e5f8943538b">always</a>(x)(y...) == x</div></div><!-- fragment --><p> for any <code>y...</code>. A copy of <code>x</code> is made and it is owned by the <code>always(x)</code> function. When <code>always(x)</code> is called, it will return a reference to the <code>x</code> it owns. This reference is valid as long as <code>always(x)</code> is in scope.</p>
  216. <h3>Example</h3>
  217. <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="always_8hpp.html">boost/hana/functional/always.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">static_assert(<a class="code" href="group__group-functional.html#ga835970cb25a0c8dc200f1e5f8943538b">hana::always</a>(1)() == 1, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(<a class="code" href="group__group-functional.html#ga835970cb25a0c8dc200f1e5f8943538b">hana::always</a>(<span class="charliteral">&#39;2&#39;</span>)(1, 2, 3) == <span class="charliteral">&#39;2&#39;</span>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  218. </div>
  219. </div>
  220. <a id="ga30027c383676084be151ef3c6cf2829f"></a>
  221. <h2 class="memtitle"><span class="permalink"><a href="#ga30027c383676084be151ef3c6cf2829f">&#9670;&nbsp;</a></span>apply</h2>
  222. <div class="memitem">
  223. <div class="memproto">
  224. <table class="memname">
  225. <tr>
  226. <td class="memname">constexpr auto boost::hana::apply</td>
  227. </tr>
  228. </table>
  229. </div><div class="memdoc">
  230. <p><code>#include &lt;<a class="el" href="apply_8hpp.html">boost/hana/functional/apply.hpp</a>&gt;</code></p>
  231. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(x)...);</div><div class="line"> }</div></div><!-- fragment -->
  232. <p>Invokes a Callable with the given arguments. </p>
  233. <p>This is equivalent to <a href="http://en.cppreference.com/w/cpp/utility/functional/invoke">std::invoke</a> that will be added in C++17. However, <code>apply</code> is a function object instead of a function, which makes it possible to pass it to higher-order algorithms.</p>
  234. <dl class="params"><dt>Parameters</dt><dd>
  235. <table class="params">
  236. <tr><td class="paramname">f</td><td>A <a href="http://en.cppreference.com/w/cpp/named_req/Callable">Callable</a> to be invoked with the given arguments.</td></tr>
  237. <tr><td class="paramname">x...</td><td>The arguments to call <code>f</code> with. The number of <code>x...</code> must match the arity of <code>f</code>.</td></tr>
  238. </table>
  239. </dd>
  240. </dl>
  241. <h2>Example </h2>
  242. <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="apply_8hpp.html">boost/hana/functional/apply.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="plus_8hpp.html">boost/hana/plus.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">static_assert(<a class="code" href="group__group-functional.html#ga30027c383676084be151ef3c6cf2829f">hana::apply</a>(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>, 1, 2) == 3, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  243. </div>
  244. </div>
  245. <a id="ga6acc765a35c4dc85f0deab4785831a3d"></a>
  246. <h2 class="memtitle"><span class="permalink"><a href="#ga6acc765a35c4dc85f0deab4785831a3d">&#9670;&nbsp;</a></span>arg</h2>
  247. <div class="memitem">
  248. <div class="memproto">
  249. <div class="memtemplate">
  250. template&lt;std::size_t n&gt; </div>
  251. <table class="memname">
  252. <tr>
  253. <td class="memname">constexpr auto boost::hana::arg</td>
  254. </tr>
  255. </table>
  256. </div><div class="memdoc">
  257. <p><code>#include &lt;<a class="el" href="arg_8hpp.html">boost/hana/functional/arg.hpp</a>&gt;</code></p>
  258. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x1, ..., <span class="keyword">auto</span>&amp;&amp; xm) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(xn);</div><div class="line"> }</div></div><!-- fragment -->
  259. <p>Return the <code>n</code>th passed argument. </p>
  260. <p>Specifically, <code>arg&lt;n&gt;(x1, ..., xn, ..., xm)</code> is equivalent to <code>xn</code>. Note that indexing starts at 1, so <code>arg&lt;1&gt;</code> returns the 1st argument, <code>arg&lt;2&gt;</code> the 2nd and so on. Using <code>arg&lt;0&gt;</code> is an error. Passing less than <code>n</code> arguments to <code>arg&lt;n&gt;</code> is also an error.</p>
  261. <dl class="tparams"><dt>Template Parameters</dt><dd>
  262. <table class="tparams">
  263. <tr><td class="paramname">n</td><td>An unsigned integer representing the argument to return. <code>n</code> must be positive (meaning nonzero).</td></tr>
  264. </table>
  265. </dd>
  266. </dl>
  267. <dl class="params"><dt>Parameters</dt><dd>
  268. <table class="params">
  269. <tr><td class="paramname">x1,...,xm</td><td>A variadic pack of arguments from which the <code>n</code>th one is returned.</td></tr>
  270. </table>
  271. </dd>
  272. </dl>
  273. <h3>Discussion: could <code>n</code> be dynamic?</h3>
  274. <p>We could have chosen <code>arg</code> to be used like <code>arg(n)(x...)</code> instead of <code>arg&lt;n&gt;(x...)</code>. Provided all the arguments were of the same type, it would then be possible for <code>n</code> to only be known at runtime. However, we would then lose the ability to assert the in-boundedness of <code>n</code> statically.</p>
  275. <h3>Rationale for <code>n</code> being a non-type template parameter</h3>
  276. <p>I claim that the only interesting use case is with a compile-time <code>n</code>, which means that the usage would become <code>arg(int_&lt;n&gt;)(x...)</code>, which is more cumbersome to write than <code>arg&lt;n&gt;(x...)</code>. This is open for discussion. </p>
  277. <h3>Example</h3>
  278. <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="arg_8hpp.html">boost/hana/functional/arg.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="comment">// hana::arg&lt;0&gt;(1, &#39;2&#39;, 3.3); // static assertion (regardless of the number of arguments)</span></div><div class="line">static_assert(hana::arg&lt;1&gt;(1, <span class="charliteral">&#39;2&#39;</span>, 3.3) == 1, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(hana::arg&lt;2&gt;(1, <span class="charliteral">&#39;2&#39;</span>, 3.3) == <span class="charliteral">&#39;2&#39;</span>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(hana::arg&lt;3&gt;(1, <span class="charliteral">&#39;2&#39;</span>, 3.3) == 3.3, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"><span class="comment">// hana::arg&lt;4&gt;(1, &#39;2&#39;, 3.3); // static assertion</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  279. </div>
  280. </div>
  281. <a id="ga41ada6b336e9d5bcb101ff0c737acbd0"></a>
  282. <h2 class="memtitle"><span class="permalink"><a href="#ga41ada6b336e9d5bcb101ff0c737acbd0">&#9670;&nbsp;</a></span>capture</h2>
  283. <div class="memitem">
  284. <div class="memproto">
  285. <table class="memname">
  286. <tr>
  287. <td class="memname">constexpr auto boost::hana::capture</td>
  288. </tr>
  289. </table>
  290. </div><div class="memdoc">
  291. <p><code>#include &lt;<a class="el" href="capture_8hpp.html">boost/hana/functional/capture.hpp</a>&gt;</code></p>
  292. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; ...variables) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...args) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(variables)..., forwarded(args)...);</div><div class="line"> };</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  293. </div><!-- fragment -->
  294. <p>Create a function capturing the given variables. </p>
  295. <p>Given 0 or more variables, <code>capture</code> creates a closure that can be used to partially apply a function. This is very similar to <code>partial</code>, except that <code>capture</code> allows the partially applied function to be specified later. Specifically, <code>capture(vars...)</code> is a function object taking a function <code>f</code> and returning <code>f</code> partially applied to <code>vars...</code>. In other words, </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>(vars...)(f)(args...) == f(vars..., args...)</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>The arity of <code>f</code> must match the total number of arguments passed to it, i.e. <code>sizeof...(vars) + sizeof...(args)</code>.</dd></dl>
  296. <h2>Example </h2>
  297. <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="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="capture_8hpp.html">boost/hana/functional/capture.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="keywordtype">int</span> main() {</div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <a class="code" href="group__group-Foldable.html#ga650def4b2e98f4273d8b9b7aa5a2fc28">sum</a> = [](<span class="keyword">auto</span> x, <span class="keyword">auto</span> y, <span class="keyword">auto</span> z) {</div><div class="line"> <span class="keywordflow">return</span> x + y + z;</div><div class="line"> };</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">hana::capture</a>(1, 2, 3)(<a class="code" href="group__group-Foldable.html#ga650def4b2e98f4273d8b9b7aa5a2fc28">sum</a>)() == 6);</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">hana::capture</a>(1, 2)(<a class="code" href="group__group-Foldable.html#ga650def4b2e98f4273d8b9b7aa5a2fc28">sum</a>)(3) == 6);</div><div class="line">}</div></div><!-- fragment -->
  298. </div>
  299. </div>
  300. <a id="ga3b16146e53efcdf9ecbb9a7b21f8cd0b"></a>
  301. <h2 class="memtitle"><span class="permalink"><a href="#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">&#9670;&nbsp;</a></span>compose</h2>
  302. <div class="memitem">
  303. <div class="memproto">
  304. <table class="memname">
  305. <tr>
  306. <td class="memname">constexpr auto boost::hana::compose</td>
  307. </tr>
  308. </table>
  309. </div><div class="memdoc">
  310. <p><code>#include &lt;<a class="el" href="compose_8hpp.html">boost/hana/functional/compose.hpp</a>&gt;</code></p>
  311. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f1, <span class="keyword">auto</span>&amp;&amp; f2, ..., <span class="keyword">auto</span>&amp;&amp; fn) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; ...xs) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f1)(</div><div class="line"> forwarded(f2)(</div><div class="line"> ...</div><div class="line"> forwarded(fn)(forwarded(x))</div><div class="line"> ),</div><div class="line"> forwarded(xs)...</div><div class="line"> );</div><div class="line"> }</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  312. </div><!-- fragment -->
  313. <p>Return the composition of two functions or more. </p>
  314. <p><code>compose</code> is defined inductively. When given more than two functions, <code>compose(f, g, h...)</code> is equivalent to <code>compose(f, compose(g, h...))</code>. When given two functions, <code>compose(f, g)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(f, g)(x, y...) == f(g(x), y...)</div></div><!-- fragment --><p>If you need composition of the form <code>f(g(x, y...))</code>, use <code>demux</code> instead.</p>
  315. <dl class="section note"><dt>Note</dt><dd><code>compose</code> is an associative operation; <code>compose(f, compose(g, h))</code> is equivalent to <code>compose(compose(f, g), h)</code>.</dd></dl>
  316. <h3>Proof of associativity</h3>
  317. <div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(f, <a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(g, h))(x, xs...) == f(<a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(g, h)(x), xs...)</div><div class="line"> == f(g(h(x)), xs...)</div><div class="line"></div><div class="line"><a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(<a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(f, g), h)(x, xs...) == <a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(f, g)(h(x), xs...)</div><div class="line"> == f(g(h(x)), xs...)</div></div><!-- fragment --> <h3>Example</h3>
  318. <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="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="compose_8hpp.html">boost/hana/functional/compose.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="keywordtype">int</span> main() {</div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> to_char = [](<span class="keywordtype">int</span> x) {</div><div class="line"> <span class="keywordflow">return</span> static_cast&lt;char&gt;(x + 48);</div><div class="line"> };</div><div class="line"></div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> increment = [](<span class="keyword">auto</span> x) {</div><div class="line"> <span class="keywordflow">return</span> x + 1;</div><div class="line"> };</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">hana::compose</a>(to_char, increment)(3) == <span class="charliteral">&#39;4&#39;</span>);</div><div class="line">}</div></div><!-- fragment -->
  319. </div>
  320. </div>
  321. <a id="ga49ea872ade5ac8f6c10052c495302e89"></a>
  322. <h2 class="memtitle"><span class="permalink"><a href="#ga49ea872ade5ac8f6c10052c495302e89">&#9670;&nbsp;</a></span>curry</h2>
  323. <div class="memitem">
  324. <div class="memproto">
  325. <div class="memtemplate">
  326. template&lt;std::size_t n&gt; </div>
  327. <table class="memname">
  328. <tr>
  329. <td class="memname">constexpr auto boost::hana::curry</td>
  330. </tr>
  331. </table>
  332. </div><div class="memdoc">
  333. <p><code>#include &lt;<a class="el" href="curry_8hpp.html">boost/hana/functional/curry.hpp</a>&gt;</code></p>
  334. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x1) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x2) {</div><div class="line"> ...</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; xn) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(</div><div class="line"> forwarded(x1), forwarded(x2), ..., forwarded(xn)</div><div class="line"> );</div><div class="line"> };</div><div class="line"> };</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  335. </div><!-- fragment -->
  336. <p>Curry a function up to the given number of arguments. </p>
  337. <p><a href="http://en.wikipedia.org/wiki/Currying">Currying</a> is a technique in which we consider a function taking multiple arguments (or, equivalently, a tuple of arguments), and turn it into a function which takes a single argument and returns a function to handle the remaining arguments. To help visualize, let's denote the type of a function <code>f</code> which takes arguments of types <code>X1, ..., Xn</code> and returns a <code>R</code> as </p><div class="fragment"><div class="line">(X1, ..., Xn) -&gt; R</div></div><!-- fragment --><p>Then, currying is the process of taking <code>f</code> and turning it into an equivalent function (call it <code>g</code>) of type </p><div class="fragment"><div class="line">X1 -&gt; (X2 -&gt; (... -&gt; (Xn -&gt; R)))</div></div><!-- fragment --><p>This gives us the following equivalence, where <code>x1</code>, ..., <code>xn</code> are objects of type <code>X1</code>, ..., <code>Xn</code> respectively: </p><div class="fragment"><div class="line">f(x1, ..., xn) == g(x1)...(xn)</div></div><!-- fragment --><p>Currying can be useful in several situations, especially when working with higher-order functions.</p>
  338. <p>This <code>curry</code> utility is an implementation of currying in C++. Specifically, <code>curry&lt;n&gt;(f)</code> is a function such that </p><div class="fragment"><div class="line">curry&lt;n&gt;(f)(x1)...(xn) == f(x1, ..., xn)</div></div><!-- fragment --><p>Note that the <code>n</code> has to be specified explicitly because the existence of functions with variadic arguments in C++ make it impossible to know when currying should stop.</p>
  339. <p>Unlike usual currying, this implementation also allows a curried function to be called with several arguments at a time. Hence, the following always holds </p><div class="fragment"><div class="line">curry&lt;n&gt;(f)(x1, ..., xk) == curry&lt;n - k&gt;(f)(x1)...(xk)</div></div><!-- fragment --><p>Of course, this requires <code>k</code> to be less than or equal to <code>n</code>; failure to satisfy this will trigger a static assertion. This syntax is supported because it makes curried functions usable where normal functions are expected.</p>
  340. <p>Another "extension" is that <code>curry&lt;0&gt;(f)</code> is supported: <code>curry&lt;0&gt;(f)</code> is a nullary function; whereas the classical definition for currying seems to leave this case undefined, as nullary functions don't make much sense in purely functional languages.</p>
  341. <h2>Example </h2>
  342. <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="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="curry_8hpp.html">boost/hana/functional/curry.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="keywordtype">int</span> main() {</div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> add = [](<span class="keyword">auto</span> x, <span class="keyword">auto</span> y, <span class="keyword">auto</span> z) {</div><div class="line"> <span class="keywordflow">return</span> x + y + z;</div><div class="line"> };</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::curry&lt;3&gt;(add)(1)(2)(3) == 1 + 2 + 3);</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::curry&lt;3&gt;(add)(1)(2, 3) == hana::curry&lt;3&gt;(add)(1)(2)(3));</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::curry&lt;3&gt;(add)(1, 2, 3) == hana::curry&lt;3&gt;(add)(1)(2)(3));</div><div class="line"></div><div class="line"> <span class="comment">// curry with a nullary function</span></div><div class="line"> BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> two = []() {</div><div class="line"> <span class="keywordflow">return</span> 2;</div><div class="line"> };</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::curry&lt;0&gt;(two)() == two());</div><div class="line">}</div></div><!-- fragment -->
  343. </div>
  344. </div>
  345. <a id="ga3a8316acd5efa22c3d1861b62d5df3c2"></a>
  346. <h2 class="memtitle"><span class="permalink"><a href="#ga3a8316acd5efa22c3d1861b62d5df3c2">&#9670;&nbsp;</a></span>demux</h2>
  347. <div class="memitem">
  348. <div class="memproto">
  349. <table class="memname">
  350. <tr>
  351. <td class="memname">constexpr auto boost::hana::demux</td>
  352. </tr>
  353. </table>
  354. </div><div class="memdoc">
  355. <p><code>#include &lt;<a class="el" href="demux_8hpp.html">boost/hana/functional/demux.hpp</a>&gt;</code></p>
  356. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...g) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> </div><div class="line"> </div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(g)(x...)...);</div><div class="line"> };</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  357. </div><!-- fragment -->
  358. <p>Invoke a function with the results of invoking other functions on its arguments. </p>
  359. <p>Specifically, <code>demux(f)(g...)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(g...)(x...) == f(g(x...)...)</div></div><!-- fragment --><p>Each <code>g</code> is called with all the arguments, and then <code>f</code> is called with the result of each <code>g</code>. Hence, the arity of <code>f</code> must match the number of <code>g</code>s.</p>
  360. <p>This is called <code>demux</code> because of a vague similarity between this device and a demultiplexer in signal processing. <code>demux</code> takes what can be seen as a continuation (<code>f</code>), a bunch of functions to split a signal (<code>g...</code>) and zero or more arguments representing the signal (<code>x...</code>). Then, it calls the continuation with the result of splitting the signal with whatever functions where given.</p>
  361. <dl class="section note"><dt>Note</dt><dd>When used with two functions only, <code>demux</code> is associative. In other words (and noting <code>demux(f, g) = demux(f)(g)</code> to ease the notation), it is true that <code>demux(demux(f, g), h) == demux(f, demux(g, h))</code>.</dd></dl>
  362. <h2>Signature </h2>
  363. <p>The signature of <code>demux</code> is </p><p class="formulaDsp">
  364. \[ \mathtt{demux} : (B_1 \times \dotsb \times B_n \to C) \to ((A_1 \times \dotsb \times A_n \to B_1) \times \dotsb \times (A_1 \times \dotsb \times A_n \to B_n)) \to (A_1 \times \dotsb \times A_n \to C) \]
  365. </p>
  366. <p>This can be rewritten more tersely as </p><p class="formulaDsp">
  367. \[ \mathtt{demux} : \left(\prod_{i=1}^n B_i \to C \right) \to \prod_{j=1}^n \left(\prod_{i=1}^n A_i \to B_j \right) \to \left(\prod_{i=1}^n A_i \to C \right) \]
  368. </p>
  369. <h2>Link with normal composition </h2>
  370. <p>The signature of <code>compose</code> is </p><p class="formulaDsp">
  371. \[ \mathtt{compose} : (B \to C) \times (A \to B) \to (A \to C) \]
  372. </p>
  373. <p>A valid observation is that this coincides exactly with the type of <code>demux</code> when used with a single unary function. Actually, both functions are equivalent: </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(g)(x) == <a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>(f, g)(x)</div></div><!-- fragment --><p>However, let's now consider the curried version of <code>compose</code>, <code>curry&lt;2&gt;(compose)</code>: </p><p class="formulaDsp">
  374. \[ \mathtt{curry_2(compose)} : (B \to C) \to ((A \to B) \to (A \to C)) \]
  375. </p>
  376. <p>For the rest of this explanation, we'll just consider the curried version of <code>compose</code> and so we'll use <code>compose</code> instead of <code>curry&lt;2&gt;(compose)</code> to lighten the notation. With currying, we can now consider <code>compose</code> applied to itself: </p><p class="formulaDsp">
  377. \[ \mathtt{compose(compose, compose)} : (B \to C) \to (A_1 \to A_2 \to B) \to (A_1 \to A_2 \to C) \]
  378. </p>
  379. <p>If we uncurry deeply the above expression, we obtain </p><p class="formulaDsp">
  380. \[ \mathtt{compose(compose, compose)} : (B \to C) \times (A_1 \times A_2 \to B) \to (A_1 \times A_2 \to C) \]
  381. </p>
  382. <p>This signature is exactly the same as that of <code>demux</code> when given a single binary function, and indeed they are equivalent definitions. We can also generalize this further by considering <code>compose(compose(compose, compose), compose)</code>: </p><p class="formulaDsp">
  383. \[ \mathtt{compose(compose(compose, compose), compose)} : (B \to C) \to (A_1 \to A_2 \to A_3 \to B) \to (A_1 \to A_2 \to A_3 \to C) \]
  384. </p>
  385. <p>which uncurries to </p><p class="formulaDsp">
  386. \[ \mathtt{compose(compose(compose, compose), compose)} : (B \to C) \times (A_1 \times A_2 \times A_3 \to B) \to (A_1 \times A_2 \times A_3 \to C) \]
  387. </p>
  388. <p>This signature is exactly the same as that of <code>demux</code> when given a single ternary function. Hence, for a single n-ary function <code>g</code>, <code>demux(f)(g)</code> is equivalent to the n-times composition of <code>compose</code> with itself, applied to <code>g</code> and <code>f</code>: </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(g) == <a class="code" href="group__group-Foldable.html#ga38c6b3f6b1cbadb9b8432a05ff16b7d2">fold_left</a>([<a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>, ..., <a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>], <span class="keywordtype">id</span>, <a class="code" href="group__group-functional.html#ga3b16146e53efcdf9ecbb9a7b21f8cd0b">compose</a>)(g, f)</div><div class="line"> <span class="comment">// ^^^^^^^^^^^^^^^^^^^^^ n times</span></div></div><!-- fragment --><p>More information on this insight can be seen <a href="http://stackoverflow.com/q/5821089/627587">here</a>. Also, I'm not sure how this insight could be generalized to more than one function <code>g</code>, or if that is even possible.</p>
  389. <h2>Proof of associativity in the binary case </h2>
  390. <p>As explained above, <code>demux</code> is associative when it is used with two functions only. Indeed, given functions <code>f</code>, <code>g</code> and <code>h</code> with suitable signatures, we have </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(<a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(g)(h))(x...) == f(<a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(g)(h)(x...))</div><div class="line"> == f(g(h(x...)))</div></div><!-- fragment --><p>On the other hand, we have </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(<a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(g))(h)(x...) == <a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">demux</a>(f)(g)(h(x...))</div><div class="line"> == f(g(h(x...)))</div></div><!-- fragment --><p>and hence <code>demux</code> is associative in the binary case.</p>
  391. <h2>Example </h2>
  392. <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="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="demux_8hpp.html">boost/hana/functional/demux.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="placeholder_8hpp.html">boost/hana/functional/placeholder.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"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"><span class="keyword">using</span> <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a>;</div><div class="line"></div><div class="line"></div><div class="line">constexpr <span class="keyword">auto</span> f = <a class="code" href="group__group-functional.html#ga3a8316acd5efa22c3d1861b62d5df3c2">hana::demux</a>(hana::make_tuple)(</div><div class="line"> <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> + <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>,</div><div class="line"> <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> - <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>,</div><div class="line"> <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> * <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>,</div><div class="line"> <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> / <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a></div><div class="line">);</div><div class="line"></div><div class="line">static_assert(</div><div class="line"> f(10, 4) == hana::make_tuple(</div><div class="line"> 10 + 4,</div><div class="line"> 10 - 4,</div><div class="line"> 10 * 4,</div><div class="line"> 10 / 4</div><div class="line"> )</div><div class="line">, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  393. </div>
  394. </div>
  395. <a id="ga1393f40da2e8da6e0c12fce953e56a6c"></a>
  396. <h2 class="memtitle"><span class="permalink"><a href="#ga1393f40da2e8da6e0c12fce953e56a6c">&#9670;&nbsp;</a></span>fix</h2>
  397. <div class="memitem">
  398. <div class="memproto">
  399. <table class="memname">
  400. <tr>
  401. <td class="memname">constexpr auto boost::hana::fix</td>
  402. </tr>
  403. </table>
  404. </div><div class="memdoc">
  405. <p><code>#include &lt;<a class="el" href="fix_8hpp.html">boost/hana/functional/fix.hpp</a>&gt;</code></p>
  406. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(<a class="code" href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">fix</a>(f), forwarded(x)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga1393f40da2e8da6e0c12fce953e56a6c"><div class="ttname"><a href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">boost::hana::fix</a></div><div class="ttdeci">constexpr auto fix</div><div class="ttdoc">Return a function computing the fixed point of a function.</div><div class="ttdef"><b>Definition:</b> fix.hpp:53</div></div>
  407. <div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  408. </div><!-- fragment -->
  409. <p>Return a function computing the fixed point of a function. </p>
  410. <p><code>fix</code> is an implementation of the <a href="http://en.wikipedia.org/wiki/Fixed-point_combinator">Y-combinator</a>, also called the fixed-point combinator. It encodes the idea of recursion, and in fact any recursive function can be written in terms of it.</p>
  411. <p>Specifically, <code>fix(f)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">fix</a>(f)(x...) == f(<a class="code" href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">fix</a>(f), x...)</div></div><!-- fragment --><p>This definition allows <code>f</code> to use its first argument as a continuation to call itself recursively. Indeed, if <code>f</code> calls its first argument with <code>y...</code>, it is equivalent to calling <code>f(fix(f), y...)</code> per the above equation.</p>
  412. <p>Most of the time, it is more convenient and efficient to define recursive functions without using a fixed-point combinator. However, there are some cases where <code>fix</code> provides either more flexibility (e.g. the ability to change the callback inside <code>f</code>) or makes it possible to write functions that couldn't be defined recursively otherwise.</p>
  413. <dl class="params"><dt>Parameters</dt><dd>
  414. <table class="params">
  415. <tr><td class="paramname">f</td><td>A function called as <code>f(self, x...)</code>, where <code>x...</code> are the arguments in the <code>fix(f)(x...)</code> expression and <code>self</code> is <code>fix(f)</code>.</td></tr>
  416. </table>
  417. </dd>
  418. </dl>
  419. <h3>Example</h3>
  420. <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="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="fix_8hpp.html">boost/hana/functional/fix.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">BOOST_HANA_CONSTEXPR_STATELESS_LAMBDA <span class="keyword">auto</span> factorial = <a class="code" href="group__group-functional.html#ga1393f40da2e8da6e0c12fce953e56a6c">hana::fix</a>([](<span class="keyword">auto</span> fact, <span class="keyword">auto</span> n) -&gt; <span class="keywordtype">int</span> {</div><div class="line"> <span class="keywordflow">if</span> (n == 0) <span class="keywordflow">return</span> 1;</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">return</span> n * fact(n - 1);</div><div class="line">});</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(factorial(5) == 120);</div><div class="line">}</div></div><!-- fragment -->
  421. </div>
  422. </div>
  423. <a id="ga004f884cdbb85c2efe3383c1db450094"></a>
  424. <h2 class="memtitle"><span class="permalink"><a href="#ga004f884cdbb85c2efe3383c1db450094">&#9670;&nbsp;</a></span>flip</h2>
  425. <div class="memitem">
  426. <div class="memproto">
  427. <table class="memname">
  428. <tr>
  429. <td class="memname">constexpr auto boost::hana::flip</td>
  430. </tr>
  431. </table>
  432. </div><div class="memdoc">
  433. <p><code>#include &lt;<a class="el" href="flip_8hpp.html">boost/hana/functional/flip.hpp</a>&gt;</code></p>
  434. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y, <span class="keyword">auto</span>&amp;&amp; ...z) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(y), forwarded(x), forwarded(z)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  435. </div><!-- fragment -->
  436. <p>Invoke a function with its two first arguments reversed. </p>
  437. <p>Specifically, <code>flip(f)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga004f884cdbb85c2efe3383c1db450094">flip</a>(f)(x, y, z...) == f(y, x, z...)</div></div><!-- fragment --><h3>Example</h3>
  438. <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="config_8hpp.html">boost/hana/config.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="flip_8hpp.html">boost/hana/functional/flip.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">BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a> = [](<span class="keywordtype">int</span> x, <span class="keywordtype">int</span> y, <span class="keywordtype">int</span> z = 0) {</div><div class="line"> <span class="keywordflow">return</span> x - y - z;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(3, 0) == 3 - 0);</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-functional.html#ga004f884cdbb85c2efe3383c1db450094">hana::flip</a>(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>)(3, 0) == 0 - 3);</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(3, 0, 1) == 3 - 0 - 1);</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(<a class="code" href="group__group-functional.html#ga004f884cdbb85c2efe3383c1db450094">hana::flip</a>(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>)(3, 0, 1) == 0 - 3 - 1);</div><div class="line">}</div></div><!-- fragment -->
  439. </div>
  440. </div>
  441. <a id="gaef38cf34324c8edbd3597ae71811d00d"></a>
  442. <h2 class="memtitle"><span class="permalink"><a href="#gaef38cf34324c8edbd3597ae71811d00d">&#9670;&nbsp;</a></span>id</h2>
  443. <div class="memitem">
  444. <div class="memproto">
  445. <table class="memname">
  446. <tr>
  447. <td class="memname">constexpr auto boost::hana::id</td>
  448. </tr>
  449. </table>
  450. </div><div class="memdoc">
  451. <p><code>#include &lt;<a class="el" href="id_8hpp.html">boost/hana/functional/id.hpp</a>&gt;</code></p>
  452. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(x);</div><div class="line"> }</div></div><!-- fragment -->
  453. <p>The identity function &ndash; returns its argument unchanged. </p>
  454. <h3>Example</h3>
  455. <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="id_8hpp.html">boost/hana/functional/id.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">static_assert(<a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">hana::id</a>(1) == 1, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(<a class="code" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d">hana::id</a>(<span class="charliteral">&#39;x&#39;</span>) == <span class="charliteral">&#39;x&#39;</span>, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  456. </div>
  457. </div>
  458. <a id="ga7bdafba6dc801f1d2d83731ad9714557"></a>
  459. <h2 class="memtitle"><span class="permalink"><a href="#ga7bdafba6dc801f1d2d83731ad9714557">&#9670;&nbsp;</a></span>infix</h2>
  460. <div class="memitem">
  461. <div class="memproto">
  462. <table class="memname">
  463. <tr>
  464. <td class="memname">constexpr auto boost::hana::infix</td>
  465. </tr>
  466. </table>
  467. </div><div class="memdoc">
  468. <p><code>#include &lt;<a class="el" href="infix_8hpp.html">boost/hana/functional/infix.hpp</a>&gt;</code></p>
  469. <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> unspecified;</div><div class="line"> }</div></div><!-- fragment -->
  470. <p>Return an equivalent function that can also be applied in infix notation. </p>
  471. <p>Specifically, <code>infix(f)</code> is an object such that: </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f)(x1, ..., xn) == f(x1, ..., xn)</div><div class="line">x ^<a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f)^ y == f(x, y)</div></div><!-- fragment --><p>Hence, the returned function can still be applied using the usual function call syntax, but it also gains the ability to be applied in infix notation. The infix syntax allows a great deal of expressiveness, especially when used in combination with some higher order algorithms. Since <code>operator^</code> is left-associative, <code>x ^infix(f)^ y</code> is actually parsed as <code>(x ^infix(f))^ y</code>. However, for flexibility, the order in which both arguments are applied in infix notation does not matter. Hence, it is always the case that </p><div class="fragment"><div class="line">(x ^ <a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f)) ^ y == x ^ (<a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f) ^ y)</div></div><!-- fragment --><p>However, note that applying more than one argument in infix notation to the same side of the operator will result in a compile-time assertion: </p><div class="fragment"><div class="line">(<a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f) ^ x) ^ y; <span class="comment">// compile-time assertion</span></div><div class="line">y ^ (x ^ <a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f)); <span class="comment">// compile-time assertion</span></div></div><!-- fragment --><p>Additionally, a function created with <code>infix</code> may be partially applied in infix notation. Specifically, </p><div class="fragment"><div class="line">(x ^ <a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f))(y1, ..., yn) == f(x, y1, ..., yn)</div><div class="line">(<a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>(f) ^ y)(x1, ..., xn) == f(x1, ..., xn, y)</div></div><!-- fragment --><h3>Rationales</h3>
  472. <ol type="1">
  473. <li>The <code>^</code> operator was chosen because it is left-associative and has a low enough priority so that most expressions will render the expected behavior.</li>
  474. <li>The operator can't be customimzed because that would require more sophistication in the implementation; I want to keep it as simple as possible. There is also an advantage in having a uniform syntax for infix application. </li>
  475. </ol>
  476. <dl class="params"><dt>Parameters</dt><dd>
  477. <table class="params">
  478. <tr><td class="paramname">f</td><td>The function which gains the ability to be applied in infix notation. The function must be at least binary; a compile-time error will be triggered otherwise.</td></tr>
  479. </table>
  480. </dd>
  481. </dl>
  482. <h3>Example</h3>
  483. <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="config_8hpp.html">boost/hana/config.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="infix_8hpp.html">boost/hana/functional/infix.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="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">BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> divmod = <a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">hana::infix</a>([](<span class="keyword">auto</span> x, <span class="keyword">auto</span> y) {</div><div class="line"> <span class="comment">// this could be a more efficient implementation</span></div><div class="line"> <span class="keywordflow">return</span> hana::make_pair(x / y, x % y);</div><div class="line">});</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>((42 ^divmod^ 23) == hana::make_pair(1, 19));</div><div class="line">}</div></div><!-- fragment -->
  484. </div>
  485. </div>
  486. <a id="gad1b8669c022d8675d68e5974451073d1"></a>
  487. <h2 class="memtitle"><span class="permalink"><a href="#gad1b8669c022d8675d68e5974451073d1">&#9670;&nbsp;</a></span>iterate</h2>
  488. <div class="memitem">
  489. <div class="memproto">
  490. <div class="memtemplate">
  491. template&lt;std::size_t n&gt; </div>
  492. <table class="memname">
  493. <tr>
  494. <td class="memname">constexpr auto boost::hana::iterate</td>
  495. </tr>
  496. </table>
  497. </div><div class="memdoc">
  498. <p><code>#include &lt;<a class="el" href="iterate_8hpp.html">boost/hana/functional/iterate.hpp</a>&gt;</code></p>
  499. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> f(f( ... f(forwarded(x))));</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  500. </div><!-- fragment -->
  501. <p>Applies another function <code>n</code> times to its argument. </p>
  502. <p>Given a function <code>f</code> and an argument <code>x</code>, <code>iterate&lt;n&gt;(f, x)</code> returns the result of applying <code>f</code> <code>n</code> times to its argument. In other words, </p><div class="fragment"><div class="line">iterate&lt;n&gt;(f, x) == f(f( ... f(x)))</div><div class="line"> ^^^^^^^^^^ n times total</div></div><!-- fragment --><p>If <code>n == 0</code>, <code>iterate&lt;n&gt;(f, x)</code> returns the <code>x</code> argument unchanged and <code>f</code> is never applied. It is important to note that the function passed to <code>iterate&lt;n&gt;</code> must be a unary function. Indeed, since <code>f</code> will be called with the result of the previous <code>f</code> application, it may only take a single argument.</p>
  503. <p>In addition to what's documented above, <code>iterate</code> can also be partially applied to the function argument out-of-the-box. In other words, <code>iterate&lt;n&gt;(f)</code> is a function object applying <code>f</code> <code>n</code> times to the argument it is called with, which means that </p><div class="fragment"><div class="line">iterate&lt;n&gt;(f)(x) == iterate&lt;n&gt;(f, x)</div></div><!-- fragment --><p>This is provided for convenience, and it turns out to be especially useful in conjunction with higher-order algorithms.</p>
  504. <h2>Signature </h2>
  505. <p>Given a function \( f : T \to T \) and <code>x</code> and argument of data type <code>T</code>, the signature is \( \mathtt{iterate_n} : (T \to T) \times T \to T \)</p>
  506. <dl class="tparams"><dt>Template Parameters</dt><dd>
  507. <table class="tparams">
  508. <tr><td class="paramname">n</td><td>An unsigned integer representing the number of times that <code>f</code> should be applied to its argument.</td></tr>
  509. </table>
  510. </dd>
  511. </dl>
  512. <dl class="params"><dt>Parameters</dt><dd>
  513. <table class="params">
  514. <tr><td class="paramname">f</td><td>A function to apply <code>n</code> times to its argument.</td></tr>
  515. <tr><td class="paramname">x</td><td>The initial value to call <code>f</code> with.</td></tr>
  516. </table>
  517. </dd>
  518. </dl>
  519. <h2>Example </h2>
  520. <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="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="iterate_8hpp.html">boost/hana/functional/iterate.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="placeholder_8hpp.html">boost/hana/functional/placeholder.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"><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> next_10 = hana::iterate&lt;10&gt;(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1);</div><div class="line">static_assert(next_10(3) == 13, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line">constexpr <span class="keyword">auto</span> xs = hana::make_tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);</div><div class="line">static_assert(hana::iterate&lt;3&gt;(hana::make_tuple, xs) ==</div><div class="line"> hana::make_tuple(hana::make_tuple(hana::make_tuple(xs))), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  521. </div>
  522. </div>
  523. <a id="gafca60c09e1f7a32a2b52baaf6515c279"></a>
  524. <h2 class="memtitle"><span class="permalink"><a href="#gafca60c09e1f7a32a2b52baaf6515c279">&#9670;&nbsp;</a></span>lockstep</h2>
  525. <div class="memitem">
  526. <div class="memproto">
  527. <table class="memname">
  528. <tr>
  529. <td class="memname">constexpr auto boost::hana::lockstep</td>
  530. </tr>
  531. </table>
  532. </div><div class="memdoc">
  533. <p><code>#include &lt;<a class="el" href="lockstep_8hpp.html">boost/hana/functional/lockstep.hpp</a>&gt;</code></p>
  534. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; ...g) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(g)(forwarded(x))...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  535. </div><!-- fragment -->
  536. <p>Invoke a function with the result of invoking other functions on its arguments, in lockstep. </p>
  537. <p>Specifically, <code>lockstep(f)(g1, ..., gN)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#gafca60c09e1f7a32a2b52baaf6515c279">lockstep</a>(f)(g1, ..., gN)(x1, ..., xN) == f(g1(x1), ..., gN(xN))</div></div><!-- fragment --><p>Since each <code>g</code> is invoked on its corresponding argument in lockstep, the number of arguments must match the number of <code>g</code>s.</p>
  538. <h2>Example </h2>
  539. <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="lockstep_8hpp.html">boost/hana/functional/lockstep.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="plus_8hpp.html">boost/hana/plus.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">constexpr <span class="keywordtype">int</span> to_int(<span class="keywordtype">char</span> c) {</div><div class="line"> <span class="keywordflow">return</span> static_cast&lt;int&gt;(c) - 48;</div><div class="line">}</div><div class="line"></div><div class="line">constexpr <span class="keywordtype">int</span> increment(<span class="keywordtype">int</span> i) {</div><div class="line"> <span class="keywordflow">return</span> i + 1;</div><div class="line">}</div><div class="line"></div><div class="line">static_assert(<a class="code" href="group__group-functional.html#gafca60c09e1f7a32a2b52baaf6515c279">hana::lockstep</a>(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>)(to_int, increment)(<span class="charliteral">&#39;3&#39;</span>, 4) == 3 + 5, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  540. </div>
  541. </div>
  542. <a id="ga35c4fc3c5677b9f558150b90e74d3ab1"></a>
  543. <h2 class="memtitle"><span class="permalink"><a href="#ga35c4fc3c5677b9f558150b90e74d3ab1">&#9670;&nbsp;</a></span>on</h2>
  544. <div class="memitem">
  545. <div class="memproto">
  546. <table class="memname">
  547. <tr>
  548. <td class="memname">constexpr auto boost::hana::on</td>
  549. </tr>
  550. </table>
  551. </div><div class="memdoc">
  552. <p><code>#include &lt;<a class="el" href="on_8hpp.html">boost/hana/functional/on.hpp</a>&gt;</code></p>
  553. <b>Initial value:</b><div class="fragment"><div class="line">= <a class="code" href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">infix</a>([](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; g) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(g(forwarded(x))...);</div><div class="line"> };</div><div class="line"> })</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  554. <div class="ttc" id="group__group-functional_html_ga7bdafba6dc801f1d2d83731ad9714557"><div class="ttname"><a href="group__group-functional.html#ga7bdafba6dc801f1d2d83731ad9714557">boost::hana::infix</a></div><div class="ttdeci">constexpr auto infix</div><div class="ttdoc">Return an equivalent function that can also be applied in infix notation.</div><div class="ttdef"><b>Definition:</b> infix.hpp:79</div></div>
  555. </div><!-- fragment -->
  556. <p>Invoke a function with the result of invoking another function on each argument. </p>
  557. <p>Specifically, <code>on(f, g)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(f, g)(x...) == f(g(x)...)</div></div><!-- fragment --><p>For convenience, <code>on</code> also supports infix application as provided by <code>infix</code>.</p>
  558. <dl class="section note"><dt>Note</dt><dd><code>on</code> is associative, i.e. <code>on(f, on(g, h))</code> is equivalent to <code>on(on(f, g), h)</code>.</dd></dl>
  559. <h3>Proof of associativity</h3>
  560. <div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(f, <a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(g, h))(xs...) == f(<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(g, h)(xs)...)</div><div class="line"> == f(g(h(xs))...)</div><div class="line"></div><div class="line"><a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(f, g), h)(xs...) == <a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>(f, g)(h(xs)...)</div><div class="line"> == f(g(h(xs))...)</div></div><!-- fragment --> <h3>Example</h3>
  561. <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="first_8hpp.html">boost/hana/first.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="on_8hpp.html">boost/hana/functional/on.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="less_8hpp.html">boost/hana/less.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="plus_8hpp.html">boost/hana/plus.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="sort_8hpp.html">boost/hana/sort.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"><span class="preprocessor">#include &lt;<a class="code" href="type_8hpp.html">boost/hana/type.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="comment">// infix application</span></div><div class="line">constexpr <span class="keyword">auto</span> sorted = <a class="code" href="group__group-Sequence.html#gac000a79eb7b9d44ecc8982c93daa40e5">hana::sort</a>.by(<a class="code" href="group__group-Orderable.html#gad510011602bdb14686f1c4ec145301c9">hana::less</a> ^<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">hana::on</a>^ <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>, hana::make_tuple(</div><div class="line"> hana::make_pair(hana::int_c&lt;3&gt;, <span class="charliteral">&#39;x&#39;</span>),</div><div class="line"> hana::make_pair(hana::int_c&lt;1&gt;, hana::type_c&lt;void&gt;),</div><div class="line"> hana::make_pair(hana::int_c&lt;2&gt;, 9876)</div><div class="line">));</div><div class="line"></div><div class="line">static_assert(sorted == hana::make_tuple(</div><div class="line"> hana::make_pair(hana::int_c&lt;1&gt;, hana::type_c&lt;void&gt;),</div><div class="line"> hana::make_pair(hana::int_c&lt;2&gt;, 9876),</div><div class="line"> hana::make_pair(hana::int_c&lt;3&gt;, <span class="charliteral">&#39;x&#39;</span>)</div><div class="line">), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// function call syntax</span></div><div class="line">constexpr <span class="keyword">auto</span> x = hana::make_pair(1, 2);</div><div class="line">constexpr <span class="keyword">auto</span> y = hana::make_pair(10, 20);</div><div class="line">static_assert(<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">hana::on</a>(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>, <a class="code" href="group__group-Product.html#ga34bbf4281de06dc3540441e8b2bd24f4">hana::first</a>)(x, y) == 1 + 10, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  562. </div>
  563. </div>
  564. <a id="ga83e71bae315e299f9f5f9de77b012139"></a>
  565. <h2 class="memtitle"><span class="permalink"><a href="#ga83e71bae315e299f9f5f9de77b012139">&#9670;&nbsp;</a></span>overload</h2>
  566. <div class="memitem">
  567. <div class="memproto">
  568. <table class="memname">
  569. <tr>
  570. <td class="memname">constexpr auto boost::hana::overload</td>
  571. </tr>
  572. </table>
  573. </div><div class="memdoc">
  574. <p><code>#include &lt;<a class="el" href="overload_8hpp.html">boost/hana/functional/overload.hpp</a>&gt;</code></p>
  575. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f1, <span class="keyword">auto</span>&amp;&amp; f2, ..., <span class="keyword">auto</span>&amp;&amp; fn) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(fk)(forwarded(x)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  576. </div><!-- fragment -->
  577. <p>Pick one of several functions to call based on overload resolution. </p>
  578. <p>Specifically, <code>overload(f1, f2, ..., fn)</code> is a function object such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga83e71bae315e299f9f5f9de77b012139">overload</a>(f1, f2, ..., fn)(x...) == fk(x...)</div></div><!-- fragment --><p>where <code>fk</code> is the function of <code>f1, ..., fn</code> that would be called if overload resolution was performed amongst that set of functions only. If more than one function <code>fk</code> would be picked by overload resolution, then the call is ambiguous.</p>
  579. <h3>Example</h3>
  580. <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="overload_8hpp.html">boost/hana/functional/overload.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></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">auto</span> on_string = [](std::string <span class="keyword">const</span>&amp; s) {</div><div class="line"> std::cout &lt;&lt; <span class="stringliteral">&quot;matched std::string: &quot;</span> &lt;&lt; s &lt;&lt; std::endl;</div><div class="line"> <span class="keywordflow">return</span> s;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">auto</span> on_int = [](<span class="keywordtype">int</span> i) {</div><div class="line"> std::cout &lt;&lt; <span class="stringliteral">&quot;matched int: &quot;</span> &lt;&lt; i &lt;&lt; std::endl;</div><div class="line"> <span class="keywordflow">return</span> i;</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">auto</span> f = <a class="code" href="group__group-functional.html#ga83e71bae315e299f9f5f9de77b012139">hana::overload</a>(on_int, on_string);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <span class="comment">// prints &quot;matched int: 1&quot;</span></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(f(1) == 1);</div><div class="line"></div><div class="line"> <span class="comment">// prints &quot;matched std::string: abcdef&quot;</span></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(f(<span class="stringliteral">&quot;abcdef&quot;</span>) == std::string{<span class="stringliteral">&quot;abcdef&quot;</span>});</div><div class="line">}</div></div><!-- fragment -->
  581. </div>
  582. </div>
  583. <a id="gaa46de6f618d9f14edb1589b36b6e75ec"></a>
  584. <h2 class="memtitle"><span class="permalink"><a href="#gaa46de6f618d9f14edb1589b36b6e75ec">&#9670;&nbsp;</a></span>overload_linearly</h2>
  585. <div class="memitem">
  586. <div class="memproto">
  587. <table class="memname">
  588. <tr>
  589. <td class="memname">constexpr auto boost::hana::overload_linearly</td>
  590. </tr>
  591. </table>
  592. </div><div class="memdoc">
  593. <p><code>#include &lt;<a class="el" href="overload__linearly_8hpp.html">boost/hana/functional/overload_linearly.hpp</a>&gt;</code></p>
  594. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f1, <span class="keyword">auto</span>&amp;&amp; f2, ..., <span class="keyword">auto</span>&amp;&amp; fn) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(fk)(forwarded(x)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  595. </div><!-- fragment -->
  596. <p>Call the first function that produces a valid call expression. </p>
  597. <p>Given functions <code>f1, ..., fn</code>, <code>overload_linearly(f1, ..., fn)</code> is a new function that calls the first <code>fk</code> producing a valid call expression with the given arguments. Specifically, </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#gaa46de6f618d9f14edb1589b36b6e75ec">overload_linearly</a>(f1, ..., fn)(args...) == fk(args...)</div></div><!-- fragment --><p>where <code>fk</code> is the <em>first</em> function such that <code>fk(args...)</code> is a valid expression.</p>
  598. <h2>Example </h2>
  599. <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="overload__linearly_8hpp.html">boost/hana/functional/overload_linearly.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">auto</span> f = <a class="code" href="group__group-functional.html#gaa46de6f618d9f14edb1589b36b6e75ec">hana::overload_linearly</a>(</div><div class="line"> [](<span class="keywordtype">int</span> i) { <span class="keywordflow">return</span> i + 1; },</div><div class="line"> [](std::string s) { <span class="keywordflow">return</span> s + <span class="stringliteral">&quot;d&quot;</span>; },</div><div class="line"> [](double) { <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(<span class="keyword">false</span> &amp;&amp; <span class="stringliteral">&quot;never called&quot;</span>); }</div><div class="line">);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(f(1) == 2);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(f(<span class="stringliteral">&quot;abc&quot;</span>) == <span class="stringliteral">&quot;abcd&quot;</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(f(2.2) == static_cast&lt;int&gt;(2.2) + 1);</div><div class="line">}</div></div><!-- fragment -->
  600. </div>
  601. </div>
  602. <a id="ga778b2daa27882e71d28b6f2b38982ddf"></a>
  603. <h2 class="memtitle"><span class="permalink"><a href="#ga778b2daa27882e71d28b6f2b38982ddf">&#9670;&nbsp;</a></span>partial</h2>
  604. <div class="memitem">
  605. <div class="memproto">
  606. <table class="memname">
  607. <tr>
  608. <td class="memname">constexpr auto boost::hana::partial</td>
  609. </tr>
  610. </table>
  611. </div><div class="memdoc">
  612. <p><code>#include &lt;<a class="el" href="partial_8hpp.html">boost/hana/functional/partial.hpp</a>&gt;</code></p>
  613. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; ...x) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...y) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(x)..., forwarded(y)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  614. </div><!-- fragment -->
  615. <p>Partially apply a function to some arguments. </p>
  616. <p>Given a function <code>f</code> and some arguments, <code>partial</code> returns a new function corresponding to the partially applied function <code>f</code>. This allows providing some arguments to a function and letting the rest of the arguments be provided later. Specifically, <code>partial(f, x...)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga778b2daa27882e71d28b6f2b38982ddf">partial</a>(f, x...)(y...) == f(x..., y...)</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>The arity of <code>f</code> must match the total number of arguments passed to it, i.e. <code>sizeof...(x) + sizeof...(y)</code>.</dd></dl>
  617. <h2>Example </h2>
  618. <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="partial_8hpp.html">boost/hana/functional/partial.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="plus_8hpp.html">boost/hana/plus.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">constexpr <span class="keyword">auto</span> increment = <a class="code" href="group__group-functional.html#ga778b2daa27882e71d28b6f2b38982ddf">hana::partial</a>(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>, 1);</div><div class="line">static_assert(increment(2) == 3, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  619. </div>
  620. </div>
  621. <a id="gaefe9fd152cba94be71c2b5b9de689d23"></a>
  622. <h2 class="memtitle"><span class="permalink"><a href="#gaefe9fd152cba94be71c2b5b9de689d23">&#9670;&nbsp;</a></span>_</h2>
  623. <div class="memitem">
  624. <div class="memproto">
  625. <table class="memname">
  626. <tr>
  627. <td class="memname">constexpr unspecified boost::hana::_ {}</td>
  628. </tr>
  629. </table>
  630. </div><div class="memdoc">
  631. <p><code>#include &lt;<a class="el" href="placeholder_8hpp.html">boost/hana/functional/placeholder.hpp</a>&gt;</code></p>
  632. <p>Create simple functions representing C++ operators inline. </p>
  633. <p>Specifically, <code>_</code> is an object used as a placeholder to build function objects representing calls to C++ operators. It works by overloading the operators between <code>_</code> and any object so that they return a function object which actually calls the corresponding operator on its argument(s). Hence, for any supported operator <code>@</code>: </p><div class="fragment"><div class="line">(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> @ <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>)(x, y) == x @ y</div></div><!-- fragment --><p>Operators may also be partially applied to one argument inline: </p><div class="fragment"><div class="line">(x @ <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>)(y) == x @ y</div><div class="line">(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> @ y)(x) == x @ y</div></div><!-- fragment --><p>When invoked with more arguments than required, functions created with <code>_</code> will discard the superfluous instead of triggering an error: </p><div class="fragment"><div class="line">(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> @ <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>)(x, y, z...) == x @ y</div></div><!-- fragment --><p>This makes functions created with <code>_</code> easier to use in higher-order algorithms, which sometime provide more information than necessary to their callbacks.</p>
  634. <h3>Supported operators</h3>
  635. <ul>
  636. <li>Arithmetic: binary <code>+</code>, binary <code>-</code>, <code>/</code>, <code>*</code>, <code>%</code>, unary <code>+</code>, unary <code>-</code></li>
  637. <li>Bitwise: <code>~</code>, <code>&amp;</code>, <code>|</code>, <code>^</code>, <code>&lt;&lt;</code>, <code>&gt;&gt;</code></li>
  638. <li>Comparison: <code>==</code>, <code>!=</code>, <code>&lt;</code>, <code>&lt;=</code>, <code>&gt;</code>, <code>&gt;=</code></li>
  639. <li>Logical: <code>||</code>, <code>&amp;&amp;</code>, <code>!</code></li>
  640. <li>Member access: <code>*</code> (dereference), <code>[]</code> (array subscript)</li>
  641. <li>Other: <code>()</code> (function call)</li>
  642. </ul>
  643. <p>More complex functionality like the ability to compose placeholders into larger function objects inline are not supported. This is on purpose; you should either use C++14 generic lambdas or a library like <a href="http://www.boost.org/doc/libs/release/libs/phoenix/doc/html/index.html">Boost.Phoenix</a> if you need bigger guns. The goal here is to save you a couple of characters in simple situations.</p>
  644. <h3>Example</h3>
  645. <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="placeholder_8hpp.html">boost/hana/functional/placeholder.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">constexpr <span class="keyword">auto</span> <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a> = <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a>;</div><div class="line">static_assert(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(1, 2) == 1 + 2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line">constexpr <span class="keyword">auto</span> increment = <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1;</div><div class="line">static_assert(increment(1) == 2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line">constexpr <span class="keyword">auto</span> twice = 2 * <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a>;</div><div class="line">static_assert(twice(1) == 2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// Extra arguments are ignored.</span></div><div class="line">static_assert(twice(1, <span class="stringliteral">&quot;ignored&quot;</span>) == 2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  646. </div>
  647. </div>
  648. <a id="ga6e648f0d3fc0209ec024e9d759a5e8f8"></a>
  649. <h2 class="memtitle"><span class="permalink"><a href="#ga6e648f0d3fc0209ec024e9d759a5e8f8">&#9670;&nbsp;</a></span>reverse_partial</h2>
  650. <div class="memitem">
  651. <div class="memproto">
  652. <table class="memname">
  653. <tr>
  654. <td class="memname">constexpr auto boost::hana::reverse_partial</td>
  655. </tr>
  656. </table>
  657. </div><div class="memdoc">
  658. <p><code>#include &lt;<a class="el" href="reverse__partial_8hpp.html">boost/hana/functional/reverse_partial.hpp</a>&gt;</code></p>
  659. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f, <span class="keyword">auto</span>&amp;&amp; ...x) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; ...y) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(y)..., forwarded(x)...);</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  660. </div><!-- fragment -->
  661. <p>Partially apply a function to some arguments. </p>
  662. <p>Given a function <code>f</code> and some arguments, <code>reverse_partial</code> returns a new function corresponding to <code>f</code> whose last arguments are partially applied. Specifically, <code>reverse_partial(f, x...)</code> is a function such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-functional.html#ga6e648f0d3fc0209ec024e9d759a5e8f8">reverse_partial</a>(f, x...)(y...) == f(y..., x...)</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>The arity of <code>f</code> must match the total number of arguments passed to it, i.e. <code>sizeof...(x) + sizeof...(y)</code>.</dd></dl>
  663. <h2>Example </h2>
  664. <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="div_8hpp.html">boost/hana/div.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="reverse__partial_8hpp.html">boost/hana/functional/reverse_partial.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">constexpr <span class="keyword">auto</span> half = <a class="code" href="group__group-functional.html#ga6e648f0d3fc0209ec024e9d759a5e8f8">hana::reverse_partial</a>(<a class="code" href="group__group-EuclideanRing.html#ga4225a7988ce98903228913dde53762df">hana::div</a>, 2);</div><div class="line">static_assert(half(4) == 2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(half(8) == 4, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
  665. </div>
  666. </div>
  667. </div><!-- contents -->
  668. </div><!-- doc-content -->
  669. <!--
  670. Copyright Louis Dionne 2013-2017
  671. Distributed under the Boost Software License, Version 1.0.
  672. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  673. -->
  674. <!-- boost-no-inspect -->
  675. <!-- HTML footer for doxygen 1.8.9.1-->
  676. <!-- start footer part -->
  677. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  678. <ul>
  679. </ul>
  680. </div>
  681. </body>
  682. </html>