Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / doc / html / structboost_1_1hana_1_1lazy.html
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.11"/>
14 <title>Boost.Hana: boost::hana::lazy&lt; implementation_defined &gt; Struct Template Reference</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   $(document).ready(initResizable);
24   $(window).load(resizeHeight);
25 </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   $(document).ready(function() { init_search(); });
31 </script>
32 <script type="text/x-mathjax-config">
33   MathJax.Hub.Config({
34     extensions: ["tex2jax.js"],
35     jax: ["input/TeX","output/HTML-CSS"],
36 });
37 // Copyright Louis Dionne 2013-2017
38 // Distributed under the Boost Software License, Version 1.0.
39 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
40 MathJax.Hub.Config({
41     "HTML-CSS": {
42         linebreaks: {
43             automatic: true,
44             width: "75% container"
45         }
46     }
47 });
48 </script><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
49 <link href="doxygen.css" rel="stylesheet" type="text/css" />
50 <!-- Additional javascript for drawing charts. -->
51 <script type="text/javascript" src="highcharts.js"></script>
52 <script type="text/javascript" src="highcharts-data.js"></script>
53 <script type="text/javascript" src="highcharts-exporting.js"></script>
54 <script type="text/javascript" src="chart.js"></script>
55 <script type="text/javascript" src="hana.js"></script>
56 </head>
57 <body>
58 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
59 <div id="titlearea">
60 <table cellspacing="0" cellpadding="0">
61  <tbody>
62  <tr style="height: 56px;">
63   <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
64   <td style="padding-left: 0.5em;">
65    <div id="projectname">Boost.Hana
66    &#160;<span id="projectnumber">1.1.0</span>
67    </div>
68    <div id="projectbrief">Your standard library for metaprogramming</div>
69   </td>
70    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
71         <span class="left">
72           <img id="MSearchSelect" src="search/mag_sel.png"
73                onmouseover="return searchBox.OnSearchSelectShow()"
74                onmouseout="return searchBox.OnSearchSelectHide()"
75                alt=""/>
76           <input type="text" id="MSearchField" value="Search" accesskey="S"
77                onfocus="searchBox.OnSearchFieldFocus(true)" 
78                onblur="searchBox.OnSearchFieldFocus(false)" 
79                onkeyup="searchBox.OnSearchFieldChange(event)"/>
80           </span><span class="right">
81             <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
82           </span>
83         </div>
84 </td>
85  </tr>
86  </tbody>
87 </table>
88 </div>
89 <!-- end header part -->
90 <!-- Generated by Doxygen 1.8.11 -->
91 <script type="text/javascript">
92 var searchBox = new SearchBox("searchBox", "search",false,'Search');
93 </script>
94 </div><!-- top -->
95 <div id="side-nav" class="ui-resizable side-nav-resizable">
96   <div id="nav-tree">
97     <div id="nav-tree-contents">
98       <div id="nav-sync" class="sync"></div>
99     </div>
100   </div>
101   <div id="splitbar" style="-moz-user-select:none;" 
102        class="ui-resizable-handle">
103   </div>
104 </div>
105 <script type="text/javascript">
106 $(document).ready(function(){initNavTree('structboost_1_1hana_1_1lazy.html','');});
107 </script>
108 <div id="doc-content">
109 <!-- window showing the filter options -->
110 <div id="MSearchSelectWindow"
111      onmouseover="return searchBox.OnSearchSelectShow()"
112      onmouseout="return searchBox.OnSearchSelectHide()"
113      onkeydown="return searchBox.OnSearchSelectKey(event)">
114 </div>
115
116 <!-- iframe showing the search results (closed by default) -->
117 <div id="MSearchResultsWindow">
118 <iframe src="javascript:void(0)" frameborder="0" 
119         name="MSearchResults" id="MSearchResults">
120 </iframe>
121 </div>
122
123 <div class="header">
124   <div class="summary">
125 <a href="#related">Synopsis of associated functions</a> &#124;
126 <a href="#friends">Friends</a> &#124;
127 <a href="structboost_1_1hana_1_1lazy-members.html">List of all members</a>  </div>
128   <div class="headertitle">
129 <div class="title">boost::hana::lazy&lt; implementation_defined &gt; Struct Template Reference<div class="ingroups"><a class="el" href="group__group-datatypes.html">Data types</a></div></div>  </div>
130 </div><!--header-->
131 <div class="contents">
132 <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
133 <div class="textblock"><h3>template&lt;typename implementation_defined&gt;<br />
134 struct boost::hana::lazy&lt; implementation_defined &gt;</h3>
135
136 <p><code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a></code> implements superficial laziness via a monadic interface. </p>
137 <p>It is important to understand that the laziness implemented by <code>lazy</code> is only superficial; only function applications made inside the <code>lazy</code> monad can be made lazy, not all their subexpressions.</p>
138 <dl class="section note"><dt>Note</dt><dd>The actual representation of <code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a></code> is completely implementation-defined. Lazy values may only be created through <code>hana::make_lazy</code>, and they can be stored in variables using <code>auto</code>, but any other assumption about the representation of <code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a>&lt;...&gt;</code> should be avoided. In particular, one should not rely on the fact that <code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a>&lt;...&gt;</code> can be pattern-matched on, because it may be a dependent type.</dd></dl>
139 <h2>Modeled concepts </h2>
140 <ol type="1">
141 <li><code>Functor</code><br />
142 Applying a function over a lazy value with <code>transform</code> returns the result of applying the function, as a lazy value. <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="eval_8hpp.html">boost/hana/eval.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="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="transform_8hpp.html">boost/hana/transform.hpp</a>&gt;</span></div><div class="line"><span class="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"><span class="keywordtype">int</span> main() {</div><div class="line">    static_assert(hana::eval(<a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::make_lazy(4 / <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>)(1), <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> * 3)) == (4 / 1) * 3, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line">    <a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::make_lazy(4 / <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a>)(0), <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">_</a> * 3); <span class="comment">// never evaluated</span></div><div class="line">}</div></div><!-- fragment --></li>
143 <li><code>Applicative</code><br />
144 A normal value can be lifted into a lazy value by using <code>lift&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;</code>. A lazy function can be lazily applied to a lazy value by using <code>ap</code>.</li>
145 <li><code>Monad</code><br />
146 The <code>lazy</code> monad allows combining lazy computations into larger lazy computations. Note that the <code>|</code> operator can be used in place of the <code>chain</code> function. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="chain_8hpp.html">boost/hana/chain.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="eval_8hpp.html">boost/hana/eval.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;functional&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;sstream&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line">T read_(std::istream&amp; stream) {</div><div class="line">    T x;</div><div class="line">    stream &gt;&gt; x;</div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;read &quot;</span> &lt;&lt; x &lt;&lt; <span class="stringliteral">&quot; from the stream\n&quot;</span>;</div><div class="line">    <span class="keywordflow">return</span> x;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line">    std::stringstream ss;</div><div class="line">    <span class="keywordtype">int</span> <a class="code" href="group__group-Searchable.html#ga0d9456ceda38b6ca664998e79d7c45b7">in</a> = 123;</div><div class="line"></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;creating the monadic chain...\n&quot;</span>;</div><div class="line">    <span class="keyword">auto</span> out = hana::make_lazy(read_&lt;int&gt;)(std::ref(ss))</div><div class="line">        | [](<span class="keyword">auto</span> x) {</div><div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;performing x + 1...\n&quot;</span>;</div><div class="line">            <span class="keywordflow">return</span> hana::make_lazy(x + 1);</div><div class="line">        }</div><div class="line">        | [](<span class="keyword">auto</span> x) {</div><div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;performing x / 2...\n&quot;</span>;</div><div class="line">            <span class="keywordflow">return</span> hana::make_lazy(x / 2);</div><div class="line">        };</div><div class="line"></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;putting &quot;</span> &lt;&lt; in &lt;&lt; <span class="stringliteral">&quot; in the stream...\n&quot;</span>;</div><div class="line">    ss &lt;&lt; <a class="code" href="group__group-Searchable.html#ga0d9456ceda38b6ca664998e79d7c45b7">in</a>; <span class="comment">// nothing is evaluated yet</span></div><div class="line"></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;evaluating the monadic chain...\n&quot;</span>;</div><div class="line">    <span class="keyword">auto</span> eout = hana::eval(out);</div><div class="line"></div><div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;the result of the monadic chain is &quot;</span> &lt;&lt; eout &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;</div><div class="line">    <a class="code" href="group__group-assertions.html#ga29b2b21ffa5513e5b706c50ffee980af">BOOST_HANA_RUNTIME_CHECK</a>(eout == (in + 1) / 2);</div><div class="line">}</div></div><!-- fragment --></li>
147 <li><code>Comonad</code><br />
148 The <code>lazy</code> comonad allows evaluating a lazy computation to get its result and lazily applying functions taking lazy inputs to lazy values. This <a href="http://ldionne.com/2015/03/16/laziness-as-a-comonad">blog post</a> goes into more details about lazy evaluation and comonads. <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="eval_8hpp.html">boost/hana/eval.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extend_8hpp.html">boost/hana/extend.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="extract_8hpp.html">boost/hana/extract.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;sstream&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">    std::stringstream s(<span class="stringliteral">&quot;1 2 3&quot;</span>);</div><div class="line">    <span class="keyword">auto</span> i = hana::make_lazy([&amp;] {</div><div class="line">        <span class="keywordtype">int</span> i;</div><div class="line">        s &gt;&gt; i;</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> i_plus_one = <a class="code" href="group__group-Comonad.html#gaf44692351fd9fe4e76815dfef6ff4478">hana::extend</a>(i, [](<span class="keyword">auto</span> lazy_int) {</div><div class="line">        <span class="keywordflow">return</span> hana::eval(lazy_int) + 1;</div><div class="line">    });</div><div class="line"></div><div class="line">    <a class="code" href="group__group-assertions.html#ga29b2b21ffa5513e5b706c50ffee980af">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(i_plus_one) == 2);</div><div class="line">    <a class="code" href="group__group-assertions.html#ga29b2b21ffa5513e5b706c50ffee980af">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(i_plus_one) == 3);</div><div class="line">    <a class="code" href="group__group-assertions.html#ga29b2b21ffa5513e5b706c50ffee980af">BOOST_HANA_RUNTIME_CHECK</a>(<a class="code" href="group__group-Comonad.html#ga307479a91a21b7ab06a2bc746b003dcc">hana::extract</a>(i_plus_one) == 4);</div><div class="line">}</div></div><!-- fragment --></li>
149 </ol>
150 <dl class="section note"><dt>Note</dt><dd><code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a></code> only models a few concepts because providing more functionality would require evaluating the lazy values in most cases. Since this raises some issues such as side effects and memoization, the interface is kept minimal. </dd></dl>
151 </div><table class="memberdecls">
152 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="related"></a>
153 Synopsis of associated functions</h2></td></tr>
154 <tr class="memitem:aae2998c08f1f80ed52a6acf57c4eec6c"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1lazy.html#aae2998c08f1f80ed52a6acf57c4eec6c">eval</a></td></tr>
155 <tr class="memdesc:aae2998c08f1f80ed52a6acf57c4eec6c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Evaluate a lazy value and return it.  <a href="#aae2998c08f1f80ed52a6acf57c4eec6c">More...</a><br /></td></tr>
156 <tr class="separator:aae2998c08f1f80ed52a6acf57c4eec6c"><td class="memSeparator" colspan="2">&#160;</td></tr>
157 <tr class="memitem:aa968ecf473c93821f1726fd9692e97f3"><td class="memTemplParams" colspan="2">template&lt;&gt; </td></tr>
158 <tr class="memitem:aa968ecf473c93821f1726fd9692e97f3"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1lazy.html#aa968ecf473c93821f1726fd9692e97f3">make&lt; lazy_tag &gt;</a></td></tr>
159 <tr class="memdesc:aa968ecf473c93821f1726fd9692e97f3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lifts a normal value to a lazy one.  <a href="#aa968ecf473c93821f1726fd9692e97f3">More...</a><br /></td></tr>
160 <tr class="separator:aa968ecf473c93821f1726fd9692e97f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
161 <tr class="memitem:a7dc86ca61b84fc42aabb525787ae61b4"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1lazy.html#a7dc86ca61b84fc42aabb525787ae61b4">make_lazy</a> = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a>&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html">lazy_tag</a>&gt;</td></tr>
162 <tr class="memdesc:a7dc86ca61b84fc42aabb525787ae61b4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Alias to <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;</code>; provided for convenience.  <a href="#a7dc86ca61b84fc42aabb525787ae61b4">More...</a><br /></td></tr>
163 <tr class="separator:a7dc86ca61b84fc42aabb525787ae61b4"><td class="memSeparator" colspan="2">&#160;</td></tr>
164 </table><table class="memberdecls">
165 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="friends"></a>
166 Friends</h2></td></tr>
167 <tr class="memitem:a97b267b09ee075f1c531b849969e75e6"><td class="memTemplParams" colspan="2"><a class="anchor" id="a97b267b09ee075f1c531b849969e75e6"></a>
168 template&lt;typename... T, typename F &gt; </td></tr>
169 <tr class="memitem:a97b267b09ee075f1c531b849969e75e6"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1lazy.html#a97b267b09ee075f1c531b849969e75e6">operator|</a> (<a class="el" href="structboost_1_1hana_1_1lazy.html">lazy</a>&lt; T... &gt;, F)</td></tr>
170 <tr class="memdesc:a97b267b09ee075f1c531b849969e75e6"><td class="mdescLeft">&#160;</td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Monad.html#ga05fdc2f887cb9967357487a432ace98b" title="Feed a monadic value into a monadic computation.Given a monadic value and a monadic function...">hana::chain</a></code>. <br /></td></tr>
171 <tr class="separator:a97b267b09ee075f1c531b849969e75e6"><td class="memSeparator" colspan="2">&#160;</td></tr>
172 </table>
173 <h2 class="groupheader">Associated functions</h2>
174 <a class="anchor" id="aae2998c08f1f80ed52a6acf57c4eec6c"></a>
175 <div class="memitem">
176 <div class="memproto">
177 <div class="memtemplate">
178 template&lt;typename implementation_defined &gt; </div>
179 <table class="mlabels">
180   <tr>
181   <td class="mlabels-left">
182       <table class="memname">
183         <tr>
184           <td class="memname">constexpr auto eval</td>
185         </tr>
186       </table>
187   </td>
188   <td class="mlabels-right">
189 <span class="mlabels"><span class="mlabel">related</span></span>  </td>
190   </tr>
191 </table>
192 </div><div class="memdoc">
193 <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; see_documentation) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line">        <span class="keywordflow">return</span> tag-dispatched;</div><div class="line">    }</div></div><!-- fragment -->
194 <p>Evaluate a lazy value and return it. </p>
195 <p>Given a lazy expression <code>expr</code>, <code>eval</code> evaluates <code>expr</code> and returns the result as a normal value. However, for convenience, <code>eval</code> can also be used with nullary and unary function objects. Specifically, if <code>expr</code> is not a <code><a class="el" href="structboost_1_1hana_1_1lazy.html" title="hana::lazy implements superficial laziness via a monadic interface. ">hana::lazy</a></code>, it is called with no arguments at all and the result of that call (<code>expr()</code>) is returned. Otherwise, if <code>expr()</code> is ill-formed, then <code>expr(hana::id)</code> is returned instead. If that expression is ill-formed, then a compile-time error is triggered.</p>
196 <p>The reason for allowing nullary callables in <code>eval</code> is because this allows using nullary lambdas as lazy branches to <code>eval_if</code>, which is convenient. The reason for allowing unary callables and calling them with <code><a class="el" href="group__group-functional.html#gaef38cf34324c8edbd3597ae71811d00d" title="The identity function – returns its argument unchanged. ">hana::id</a></code> is because this allows deferring the compile-time evaluation of selected expressions inside the callable. How this can be achieved is documented by <code><a class="el" href="group__group-Logical.html#gab64636f84de983575aac0208f5fa840c" title="Conditionally execute one of two branches based on a condition.Given a condition and two branches in ...">hana::eval_if</a></code>.</p>
197 <h2>Example </h2>
198 <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="eval_8hpp.html">boost/hana/eval.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="lazy_8hpp.html">boost/hana/lazy.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(hana::eval(hana::make_lazy(<a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1)(3)) == 4, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --> 
199 </div>
200 </div>
201 <a class="anchor" id="aa968ecf473c93821f1726fd9692e97f3"></a>
202 <div class="memitem">
203 <div class="memproto">
204 <div class="memtemplate">
205 template&lt;typename implementation_defined &gt; </div>
206 <div class="memtemplate">
207 template&lt;&gt; </div>
208 <table class="mlabels">
209   <tr>
210   <td class="mlabels-left">
211       <table class="memname">
212         <tr>
213           <td class="memname">constexpr auto <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a>&lt; <a class="el" href="structboost_1_1hana_1_1lazy__tag.html">lazy_tag</a> &gt;</td>
214         </tr>
215       </table>
216   </td>
217   <td class="mlabels-right">
218 <span class="mlabels"><span class="mlabel">related</span></span>  </td>
219   </tr>
220 </table>
221 </div><div class="memdoc">
222 <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> lazy&lt;implementation_defined&gt;{forwarded(x)};</div><div class="line">    }</div></div><!-- fragment -->
223 <p>Lifts a normal value to a lazy one. </p>
224 <p><code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;</code> can be used to lift a normal value or a function call into a lazy expression. Precisely, <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;(x)</code> is a lazy value equal to <code>x</code>, and <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;(f)(x1, ..., xN)</code> is a lazy function call that is equal to <code>f(x1, ..., xN)</code> when it is <code>eval</code>uated.</p>
225 <dl class="section note"><dt>Note</dt><dd>It is interesting to note that <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;(f)(x1, ..., xN)</code> is equivalent to <div class="fragment"><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(<a class="code" href="structboost_1_1hana_1_1lazy.html#aa968ecf473c93821f1726fd9692e97f3">make&lt;lazy_tag&gt;</a>(f), lift&lt;lazy_tag&gt;(x1), ..., lift&lt;lazy_tag&gt;(xN))</div></div><!-- fragment --> which in turn is equivalent to <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;(f(x1, ..., xN))</code>, except for the fact that the inner call to <code>f</code> is evaluated lazily.</dd></dl>
226 <h2>Example </h2>
227 <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="bool_8hpp.html">boost/hana/bool.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="eval_8hpp.html">boost/hana/eval.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="if_8hpp.html">boost/hana/if.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.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> f = hana::make&lt;hana::lazy_tag&gt;([](<span class="keyword">auto</span> x) {</div><div class="line">        <span class="keywordflow">return</span> 1 / x;</div><div class="line">    });</div><div class="line"></div><div class="line">    BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> g = hana::make_lazy([](<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#ga5150cd7df438a22056a39529d21562d2">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::eval(<a class="code" href="group__group-Logical.html#gafd655d2222367131e7a63616e93dd080">hana::if_</a>(hana::false_c, f(0), g(0))) == 0 + 1);</div><div class="line">}</div></div><!-- fragment --> 
228 </div>
229 </div>
230 <a class="anchor" id="a7dc86ca61b84fc42aabb525787ae61b4"></a>
231 <div class="memitem">
232 <div class="memproto">
233 <div class="memtemplate">
234 template&lt;typename implementation_defined &gt; </div>
235 <table class="mlabels">
236   <tr>
237   <td class="mlabels-left">
238       <table class="memname">
239         <tr>
240           <td class="memname">constexpr auto make_lazy = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a>&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html">lazy_tag</a>&gt;</td>
241         </tr>
242       </table>
243   </td>
244   <td class="mlabels-right">
245 <span class="mlabels"><span class="mlabel">related</span></span>  </td>
246   </tr>
247 </table>
248 </div><div class="memdoc">
249
250 <p>Alias to <code>make&lt;<a class="el" href="structboost_1_1hana_1_1lazy__tag.html" title="Tag representing hana::lazy. ">lazy_tag</a>&gt;</code>; provided for convenience. </p>
251 <h2>Example </h2>
252 <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="bool_8hpp.html">boost/hana/bool.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="eval_8hpp.html">boost/hana/eval.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="if_8hpp.html">boost/hana/if.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="lazy_8hpp.html">boost/hana/lazy.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> f = hana::make&lt;hana::lazy_tag&gt;([](<span class="keyword">auto</span> x) {</div><div class="line">        <span class="keywordflow">return</span> 1 / x;</div><div class="line">    });</div><div class="line"></div><div class="line">    BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> g = hana::make_lazy([](<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#ga5150cd7df438a22056a39529d21562d2">BOOST_HANA_CONSTEXPR_CHECK</a>(hana::eval(<a class="code" href="group__group-Logical.html#gafd655d2222367131e7a63616e93dd080">hana::if_</a>(hana::false_c, f(0), g(0))) == 0 + 1);</div><div class="line">}</div></div><!-- fragment --> 
253 </div>
254 </div>
255 </div><!-- contents -->
256 </div><!-- doc-content -->
257 <!--
258 Copyright Louis Dionne 2013-2017
259 Distributed under the Boost Software License, Version 1.0.
260 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
261 -->
262 <!-- boost-no-inspect -->
263 <!-- HTML footer for doxygen 1.8.9.1-->
264 <!-- start footer part -->
265 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
266   <ul>
267     <li class="navelem"><a class="el" href="namespaceboost.html">boost</a></li><li class="navelem"><a class="el" href="namespaceboost_1_1hana.html">hana</a></li><li class="navelem"><a class="el" href="structboost_1_1hana_1_1lazy.html">lazy</a></li>
268   </ul>
269 </div>
270 </body>
271 </html>