123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 |
- <!--
- Copyright Louis Dionne 2013-2017
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
- -->
- <!-- boost-no-inspect -->
- <!-- HTML header for doxygen 1.8.9.1-->
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.15"/>
- <title>Boost.Hana: boost::hana::optional< T > Struct Template Reference</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="navtree.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="resize.js"></script>
- <script type="text/javascript" src="navtreedata.js"></script>
- <script type="text/javascript" src="navtree.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(document).ready(initResizable);
- /* @license-end */</script>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/searchdata.js"></script>
- <script type="text/javascript" src="search/search.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(document).ready(function() { init_search(); });
- /* @license-end */
- </script>
- <script type="text/x-mathjax-config">
- MathJax.Hub.Config({
- extensions: ["tex2jax.js"],
- jax: ["input/TeX","output/HTML-CSS"],
- });
- // Copyright Louis Dionne 2013-2017
- // Distributed under the Boost Software License, Version 1.0.
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
- MathJax.Hub.Config({
- "HTML-CSS": {
- linebreaks: {
- automatic: true,
- width: "75% container"
- }
- }
- });
- </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- <!-- Additional javascript for drawing charts. -->
- <script type="text/javascript" src="highcharts.js"></script>
- <script type="text/javascript" src="highcharts-data.js"></script>
- <script type="text/javascript" src="highcharts-exporting.js"></script>
- <script type="text/javascript" src="chart.js"></script>
- <script type="text/javascript" src="hana.js"></script>
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
- <td style="padding-left: 0.5em;">
- <div id="projectname">Boost.Hana
-  <span id="projectnumber">1.6.0</span>
- </div>
- <div id="projectbrief">Your standard library for metaprogramming</div>
- </td>
- <td> <div id="MSearchBox" class="MSearchBoxInactive">
- <span class="left">
- <img id="MSearchSelect" src="search/mag_sel.png"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- alt=""/>
- <input type="text" id="MSearchField" value="Search" accesskey="S"
- onfocus="searchBox.OnSearchFieldFocus(true)"
- onblur="searchBox.OnSearchFieldFocus(false)"
- onkeyup="searchBox.OnSearchFieldChange(event)"/>
- </span><span class="right">
- <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
- </span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.15 -->
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- /* @license-end */
- </script>
- </div><!-- top -->
- <div id="side-nav" class="ui-resizable side-nav-resizable">
- <div id="nav-tree">
- <div id="nav-tree-contents">
- <div id="nav-sync" class="sync"></div>
- </div>
- </div>
- <div id="splitbar" style="-moz-user-select:none;"
- class="ui-resizable-handle">
- </div>
- </div>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(document).ready(function(){initNavTree('structboost_1_1hana_1_1optional.html','');});
- /* @license-end */
- </script>
- <div id="doc-content">
- <!-- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- </div>
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="javascript:void(0)" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
- <div class="header">
- <div class="summary">
- <a href="#related">Synopsis of associated functions</a> |
- <a href="#friends">Friends</a> |
- <a href="#pub-methods">Public Member Functions</a> |
- <a href="structboost_1_1hana_1_1optional-members.html">List of all members</a> </div>
- <div class="headertitle">
- <div class="title">boost::hana::optional< T > Struct Template Reference<div class="ingroups"><a class="el" href="group__group-datatypes.html">Data types</a></div></div> </div>
- </div><!--header-->
- <div class="contents">
- <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
- <div class="textblock"><h3>template<typename ... T><br />
- struct boost::hana::optional< T ></h3>
- <p>Optional value whose optional-ness is known at compile-time. </p>
- <p>An <code>optional</code> either contains a value (represented as <code>just(x)</code>), or it is empty (represented as <code>nothing</code>). In essence, <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code> is pretty much like a <code>boost::optional</code> or the upcoming <code>std::optional</code>, except for the fact that whether a <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code> is empty or not is known at compile-time. This can be particularly useful for returning from a function that might fail, but whose reason for failing is not important. Of course, whether the function will fail has to be known at compile-time.</p>
- <p>This is really an important difference between <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code> and <code>std::optional</code>. Unlike <code>std::optional<T>{}</code> and <code>std::optional<T>{x}</code> who share the same type (<code>std::optional<T></code>), <code>hana::just(x)</code> and <code>hana::nothing</code> do not share the same type, since the state of the optional has to be known at compile-time. Hence, whether a <code>hana::just</code> or a <code>hana::nothing</code> will be returned from a function has to be known at compile-time for the return type of that function to be computable by the compiler. This makes <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code> well suited for static metaprogramming tasks, but very poor for anything dynamic.</p>
- <dl class="section note"><dt>Note</dt><dd>When you use a container, remember not to make assumptions about its representation, unless the documentation gives you those guarantees. More details <a class="el" href="index.html#tutorial-containers-types">in the tutorial</a>.</dd></dl>
- <h2>Interoperation with <code>type</code>s </h2>
- <p>When a <code>just</code> contains an object of type <code>T</code> which is a <code>type</code>, it has a nested <code>::type</code> alias equivalent to <code>T::type</code>. <code>nothing</code>, however, never has a nested <code>::type</code> alias. If <code>t</code> is a <code>type</code>, this allows <code>decltype(just(t))</code> to be seen as a nullary metafunction equivalent to <code>decltype(t)</code>. Along with the <code>sfinae</code> function, this allows <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code> to interact seamlessly with SFINAE-friendly metafunctions. Example: </p><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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="not_8hpp.html">boost/hana/not.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="traits_8hpp.html">boost/hana/traits.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <type_traits></span></div><div class="line"><span class="preprocessor">#include <utility></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> <<span class="keyword">typename</span> ...></div><div class="line"><span class="keyword">using</span> void_t = void;</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> T, <span class="keyword">typename</span> = <span class="keywordtype">void</span>></div><div class="line"><span class="keyword">struct </span>has_type : std::false_type { };</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><span class="keyword">struct </span>has_type<T, void_t<typename T::type>></div><div class="line"> : std::true_type</div><div class="line">{ };</div><div class="line"></div><div class="line"><span class="keyword">auto</span> common_type_impl = hana::sfinae([](<span class="keyword">auto</span> t, <span class="keyword">auto</span> u) -> hana::type<</div><div class="line"> decltype(<span class="keyword">true</span> ? hana::traits::declval(t) : hana::traits::declval(u))</div><div class="line">> { <span class="keywordflow">return</span> {}; });</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> T, <span class="keyword">typename</span> U></div><div class="line"><span class="keyword">using</span> common_type = decltype(common_type_impl(hana::type_c<T>, hana::type_c<U>));</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(</div><div class="line"> common_type_impl(hana::type_c<int>, hana::type_c<float>)</div><div class="line"> ==</div><div class="line"> hana::just(hana::type_c<float>)</div><div class="line">);</div><div class="line"></div><div class="line">static_assert(!has_type<common_type<int, int*>>{}, <span class="stringliteral">""</span>);</div><div class="line">static_assert(std::is_same<common_type<int, float>::type, <span class="keywordtype">float</span>>{}, <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --><h2>Modeled concepts </h2>
- <ol type="1">
- <li><code>Comparable</code><br />
- Two <code>optional</code>s are equal if and only if they are both empty or they both contain a value and those values are equal. <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::nothing == hana::nothing);</div><div class="line">static_assert(hana::just(<span class="charliteral">'x'</span>) == hana::just(<span class="charliteral">'x'</span>), <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::just(<span class="charliteral">'x'</span>) != hana::just(<span class="charliteral">'y'</span>), <span class="stringliteral">""</span>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::just(<span class="charliteral">'x'</span>) != hana::nothing);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Orderable</code><br />
- Optional values can be ordered by considering the value they are holding, if any. To handle the case of an empty optional value, we arbitrarily set <code>nothing</code> as being less than any other <code>just</code>. Hence, <div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x) < <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(y) <span class="keywordflow">if</span> and only <span class="keywordflow">if</span> x < y</div><div class="line"><a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a> < <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(anything)</div></div><!-- fragment --> Example: <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="greater_8hpp.html">boost/hana/greater.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="less_8hpp.html">boost/hana/less.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::nothing < hana::just(3));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::just(0) > hana::nothing);</div><div class="line">static_assert(hana::just(1) < hana::just(3), <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::just(3) > hana::just(2), <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Functor</code><br />
- An optional value can be seen as a list containing either one element (<code>just(x)</code>) or no elements at all (<code>nothing</code>). As such, mapping a function over an optional value is equivalent to applying it to its value if there is one, and to <code>nothing</code> otherwise: <div class="fragment"><div class="line"><a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(<a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x), f) == <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(f(x))</div><div class="line"><a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">transform</a>(<a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>, f) == <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a></div></div><!-- fragment --> Example: <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="placeholder_8hpp.html">boost/hana/functional/placeholder.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="transform_8hpp.html">boost/hana/transform.hpp</a>></span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::nothing, <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1) == hana::nothing);</div><div class="line">static_assert(<a class="code" href="group__group-Functor.html#ga5a8975f6e55375d5b6038a9c36ee63e7">hana::transform</a>(hana::just(1), <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1) == hana::just(2), <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Applicative</code><br />
- First, a value can be made optional with <code>lift<<a class="el" href="structboost_1_1hana_1_1optional__tag.html" title="Tag representing a hana::optional.">optional_tag</a>></code>, which is equivalent to <code>just</code>. Second, one can feed an optional value to an optional function with <code>ap</code>, which will return <code>just(f(x))</code> if there is both a function <em>and</em> a value, and <code>nothing</code> otherwise: <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_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(f), <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x)) == <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(f(x))</div><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(<a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>, <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x)) == <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a></div><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(<a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(f), <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>) == <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a></div><div class="line"><a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">ap</a>(<a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>, <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>) == <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a></div></div><!-- fragment --> A simple example: <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 <<a class="code" href="ap_8hpp.html">boost/hana/ap.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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">char</span> next(<span class="keywordtype">char</span> c) { <span class="keywordflow">return</span> c + 1; }</div><div class="line"></div><div class="line">static_assert(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::just(next), hana::just(<span class="charliteral">'x'</span>)) == hana::just(<span class="charliteral">'y'</span>), <span class="stringliteral">""</span>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::nothing, hana::just(<span class="charliteral">'x'</span>)) == hana::nothing);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::just(next), hana::nothing) == hana::nothing);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(hana::nothing, hana::nothing) == hana::nothing);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --> A more complex example: <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 <<a class="code" href="ap_8hpp.html">boost/hana/ap.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="bool_8hpp.html">boost/hana/bool.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="config_8hpp.html">boost/hana/config.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="if_8hpp.html">boost/hana/if.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="lift_8hpp.html">boost/hana/lift.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> <<span class="keywordtype">char</span> op></div><div class="line">constexpr <span class="keyword">auto</span> <span class="keyword">function</span> = hana::nothing;</div><div class="line"></div><div class="line"><span class="keyword">template</span> <></div><div class="line">BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> function<'+'> = hana::just([](<span class="keyword">auto</span> x, <span class="keyword">auto</span> y) {</div><div class="line"> <span class="keywordflow">return</span> x + y;</div><div class="line">});</div><div class="line"></div><div class="line"><span class="keyword">template</span> <></div><div class="line">BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> <span class="keyword">function</span><<span class="charliteral">'-'</span>> = hana::just([](<span class="keyword">auto</span> x, <span class="keyword">auto</span> y) {</div><div class="line"> <span class="keywordflow">return</span> x - y;</div><div class="line">});</div><div class="line"></div><div class="line"><span class="comment">// and so on...</span></div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keywordtype">char</span> n></div><div class="line">constexpr <span class="keyword">auto</span> digit = <a class="code" href="group__group-Logical.html#gafd655d2222367131e7a63616e93dd080">hana::if_</a>(hana::bool_c<(n >= <span class="charliteral">'0'</span> && n <= <span class="charliteral">'9'</span>)>,</div><div class="line"> hana::just(static_cast<int>(n - 48)),</div><div class="line"> hana::nothing</div><div class="line">);</div><div class="line"></div><div class="line"><span class="keyword">template</span> <<span class="keywordtype">char</span> x, <span class="keywordtype">char</span> op, <span class="keywordtype">char</span> y></div><div class="line">BOOST_HANA_CONSTEXPR_LAMBDA <span class="keyword">auto</span> evaluate = <a class="code" href="group__group-Applicative.html#ga6176a32953dbbdee96e3ab3c73e4c890">hana::ap</a>(function<op>, digit<x>, digit<y>);</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>(evaluate<'1', '+', '2'> == hana::just(1 + 2));</div><div class="line"> <a class="code" href="group__group-assertions.html#gac7aafc41e4dcc7d1f1929fb00f010d2a">BOOST_HANA_CONSTEXPR_CHECK</a>(evaluate<'4', '-', '2'> == hana::just(4 - 2));</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(evaluate<'?', '+', '2'> == hana::nothing);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(evaluate<'1', '?', '2'> == hana::nothing);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(evaluate<'1', '+', '?'> == hana::nothing);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(evaluate<'?', '?', '?'> == hana::nothing);</div><div class="line"></div><div class="line"> static_assert(hana::lift<hana::optional_tag>(123) == hana::just(123), <span class="stringliteral">""</span>);</div><div class="line">}</div></div><!-- fragment --></li>
- <li><code>Monad</code><br />
- The <code>Monad</code> model makes it easy to compose actions that might fail. One can feed an optional value if there is one into a function with <code>chain</code>, which will return <code>nothing</code> if there is no value. Finally, optional-optional values can have their redundant level of optionality removed with <code>flatten</code>. Also note that the <code>|</code> operator can be used in place of the <code>chain</code> function. Example: <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="chain_8hpp.html">boost/hana/chain.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="config_8hpp.html">boost/hana/config.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="flatten_8hpp.html">boost/hana/flatten.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> inc = [](<span class="keyword">auto</span> x) {</div><div class="line"> <span class="keywordflow">return</span> hana::just(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-Monad.html#ga05fdc2f887cb9967357487a432ace98b">hana::chain</a>(hana::just(1), inc) == hana::just(2));</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Monad.html#ga05fdc2f887cb9967357487a432ace98b">hana::chain</a>(hana::nothing, inc) == hana::nothing);</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-Monad.html#gaa5fec6fb418de5da3ecb500fd6cc54dd">hana::flatten</a>(hana::just(hana::just(2))) == hana::just(2));</div><div class="line">}</div></div><!-- fragment --></li>
- <li><code>MonadPlus</code><br />
- The <code>MonadPlus</code> model allows choosing the first valid value out of two optional values with <code>concat</code>. If both optional values are <code>nothing</code>s, <code>concat</code> will return <code>nothing</code>. Example: <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="concat_8hpp.html">boost/hana/concat.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="empty_8hpp.html">boost/hana/empty.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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-MonadPlus.html#ga1946e96c3b4c178c7ae8703724c29c37">hana::concat</a>(hana::nothing, hana::just(<span class="charliteral">'x'</span>)) == hana::just(<span class="charliteral">'x'</span>), <span class="stringliteral">""</span>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-MonadPlus.html#ga1946e96c3b4c178c7ae8703724c29c37">hana::concat</a>(hana::nothing, hana::nothing) == hana::nothing);</div><div class="line">static_assert(<a class="code" href="group__group-MonadPlus.html#ga1946e96c3b4c178c7ae8703724c29c37">hana::concat</a>(hana::just(<span class="charliteral">'x'</span>), hana::just(<span class="charliteral">'y'</span>)) == hana::just(<span class="charliteral">'x'</span>), <span class="stringliteral">""</span>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::empty<hana::optional_tag>() == hana::nothing);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Foldable</code><br />
- Folding an optional value is equivalent to folding a list containing either no elements (for <code>nothing</code>) or <code>x</code> (for <code>just(x)</code>). Example: <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 <<a class="code" href="fold__right_8hpp.html">boost/hana/fold_right.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="plus_8hpp.html">boost/hana/plus.hpp</a>></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-Foldable.html#ga77d43badebd59b046cf93598733649b4">hana::fold_right</a>(hana::nothing, 1, <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>) == 1, <span class="stringliteral">""</span>);</div><div class="line">static_assert(<a class="code" href="group__group-Foldable.html#ga77d43badebd59b046cf93598733649b4">hana::fold_right</a>(hana::just(4), 1, <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">hana::plus</a>) == 5, <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Searchable</code><br />
- Searching an optional value is equivalent to searching a list containing <code>x</code> for <code>just(x)</code> and an empty list for <code>nothing</code>. Example: <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 <<a class="code" href="all__of_8hpp.html">boost/hana/all_of.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="find__if_8hpp.html">boost/hana/find_if.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="integral__constant_8hpp.html">boost/hana/integral_constant.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="mod_8hpp.html">boost/hana/mod.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> odd = [](<span class="keyword">auto</span> x) {</div><div class="line"> <span class="keywordflow">return</span> x % hana::int_c<2> != hana::int_c<0>;</div><div class="line">};</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga7f99b80672aa80a7eb8b223955ce546f">hana::find_if</a>(hana::just(hana::int_c<3>), odd) == hana::just(hana::int_c<3>));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga7f99b80672aa80a7eb8b223955ce546f">hana::find_if</a>(hana::just(hana::int_c<2>), odd) == hana::nothing);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga7f99b80672aa80a7eb8b223955ce546f">hana::find_if</a>(hana::nothing, odd) == hana::nothing);</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga3a168950082f38afd9edf256f336c8ba">hana::all_of</a>(hana::just(hana::int_c<3>), odd));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Searchable.html#ga3a168950082f38afd9edf256f336c8ba">hana::all_of</a>(hana::nothing, odd));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --> </li>
- </ol>
- </div><table class="memberdecls">
- <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="related"></a>
- Synopsis of associated functions</h2></td></tr>
- <tr class="memitem:a76a84854b3051af000e698157d63a6a8"><td class="memTemplParams" colspan="2">template<> </td></tr>
- <tr class="memitem:a76a84854b3051af000e698157d63a6a8"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a76a84854b3051af000e698157d63a6a8">make< optional_tag ></a></td></tr>
- <tr class="memdesc:a76a84854b3051af000e698157d63a6a8"><td class="mdescLeft"> </td><td class="mdescRight">Create an optional value. <a href="#a76a84854b3051af000e698157d63a6a8">More...</a><br /></td></tr>
- <tr class="separator:a76a84854b3051af000e698157d63a6a8"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:af1105a435d6435a2437cb5dc162ba463"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#af1105a435d6435a2437cb5dc162ba463">make_optional</a> = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a><<a class="el" href="structboost_1_1hana_1_1optional__tag.html">optional_tag</a>></td></tr>
- <tr class="memdesc:af1105a435d6435a2437cb5dc162ba463"><td class="mdescLeft"> </td><td class="mdescRight">Alias to <code>make<<a class="el" href="structboost_1_1hana_1_1optional__tag.html" title="Tag representing a hana::optional.">optional_tag</a>></code>; provided for convenience. <a href="#af1105a435d6435a2437cb5dc162ba463">More...</a><br /></td></tr>
- <tr class="separator:af1105a435d6435a2437cb5dc162ba463"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a8ad818d6df7379b0adefa45d2ac844d0"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a></td></tr>
- <tr class="memdesc:a8ad818d6df7379b0adefa45d2ac844d0"><td class="mdescLeft"> </td><td class="mdescRight">Create an optional value containing <code>x</code>. <a href="#a8ad818d6df7379b0adefa45d2ac844d0">More...</a><br /></td></tr>
- <tr class="separator:a8ad818d6df7379b0adefa45d2ac844d0"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a0c315287473aa87fe5ccd9d8a1c10186"><td class="memItemLeft" align="right" valign="top">constexpr <a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a> {}</td></tr>
- <tr class="memdesc:a0c315287473aa87fe5ccd9d8a1c10186"><td class="mdescLeft"> </td><td class="mdescRight">An empty optional value. <a href="#a0c315287473aa87fe5ccd9d8a1c10186">More...</a><br /></td></tr>
- <tr class="separator:a0c315287473aa87fe5ccd9d8a1c10186"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a6529e11cb228e99a05e81071752807d5"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a6529e11cb228e99a05e81071752807d5">maybe</a></td></tr>
- <tr class="memdesc:a6529e11cb228e99a05e81071752807d5"><td class="mdescLeft"> </td><td class="mdescRight">Apply a function to the contents of an optional, with a fallback result. <a href="#a6529e11cb228e99a05e81071752807d5">More...</a><br /></td></tr>
- <tr class="separator:a6529e11cb228e99a05e81071752807d5"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:aa4c8c0b1ef3d8206974734b93646c9fd"><td class="memItemLeft" align="right" valign="top">auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#aa4c8c0b1ef3d8206974734b93646c9fd">sfinae</a></td></tr>
- <tr class="memdesc:aa4c8c0b1ef3d8206974734b93646c9fd"><td class="mdescLeft"> </td><td class="mdescRight">Calls a function if the call expression is well-formed. <a href="#aa4c8c0b1ef3d8206974734b93646c9fd">More...</a><br /></td></tr>
- <tr class="separator:aa4c8c0b1ef3d8206974734b93646c9fd"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a1047a69893a62cd36eb0d2934f85e0e7"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a1047a69893a62cd36eb0d2934f85e0e7">is_just</a></td></tr>
- <tr class="memdesc:a1047a69893a62cd36eb0d2934f85e0e7"><td class="mdescLeft"> </td><td class="mdescRight">Return whether an <code>optional</code> contains a value. <a href="#a1047a69893a62cd36eb0d2934f85e0e7">More...</a><br /></td></tr>
- <tr class="separator:a1047a69893a62cd36eb0d2934f85e0e7"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a4eb266d123883c23853f7731a6c5953f"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a4eb266d123883c23853f7731a6c5953f">is_nothing</a></td></tr>
- <tr class="memdesc:a4eb266d123883c23853f7731a6c5953f"><td class="mdescLeft"> </td><td class="mdescRight">Return whether an <code>optional</code> is empty. <a href="#a4eb266d123883c23853f7731a6c5953f">More...</a><br /></td></tr>
- <tr class="separator:a4eb266d123883c23853f7731a6c5953f"><td class="memSeparator" colspan="2"> </td></tr>
- </table><table class="memberdecls">
- <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="friends"></a>
- Friends</h2></td></tr>
- <tr class="memitem:a833b9d5d44bb431621af9129994b9bbc"><td class="memTemplParams" colspan="2"><a id="a833b9d5d44bb431621af9129994b9bbc"></a>
- template<typename ... T, typename F > </td></tr>
- <tr class="memitem:a833b9d5d44bb431621af9129994b9bbc"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a833b9d5d44bb431621af9129994b9bbc">operator|</a> (<a class="el" href="structboost_1_1hana_1_1optional.html">optional</a>< T... >, F)</td></tr>
- <tr class="memdesc:a833b9d5d44bb431621af9129994b9bbc"><td class="mdescLeft"> </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>
- <tr class="separator:a833b9d5d44bb431621af9129994b9bbc"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a27607958295e6da8a0ba602a2db468f1"><td class="memTemplParams" colspan="2"><a id="a27607958295e6da8a0ba602a2db468f1"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:a27607958295e6da8a0ba602a2db468f1"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a27607958295e6da8a0ba602a2db468f1">operator==</a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:a27607958295e6da8a0ba602a2db468f1"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547" title="Returns a Logical representing whether x is equal to y.The equal function can be called in two differ...">hana::equal</a></code> <br /></td></tr>
- <tr class="separator:a27607958295e6da8a0ba602a2db468f1"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a0cae3af55edb3eb05bfa184bda633f7d"><td class="memTemplParams" colspan="2"><a id="a0cae3af55edb3eb05bfa184bda633f7d"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:a0cae3af55edb3eb05bfa184bda633f7d"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a0cae3af55edb3eb05bfa184bda633f7d">operator!=</a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:a0cae3af55edb3eb05bfa184bda633f7d"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd" title="Returns a Logical representing whether x is not equal to y.The not_equal function can be called in tw...">hana::not_equal</a></code> <br /></td></tr>
- <tr class="separator:a0cae3af55edb3eb05bfa184bda633f7d"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:ada078dcf9e68b8e9a82b33c75dde8457"><td class="memTemplParams" colspan="2"><a id="ada078dcf9e68b8e9a82b33c75dde8457"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:ada078dcf9e68b8e9a82b33c75dde8457"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#ada078dcf9e68b8e9a82b33c75dde8457">operator<</a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:ada078dcf9e68b8e9a82b33c75dde8457"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Orderable.html#gad510011602bdb14686f1c4ec145301c9" title="Returns a Logical representing whether x is less than y.">hana::less</a></code> <br /></td></tr>
- <tr class="separator:ada078dcf9e68b8e9a82b33c75dde8457"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:aedd11fddefddbbbb87d3b24c7117528f"><td class="memTemplParams" colspan="2"><a id="aedd11fddefddbbbb87d3b24c7117528f"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:aedd11fddefddbbbb87d3b24c7117528f"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#aedd11fddefddbbbb87d3b24c7117528f">operator></a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:aedd11fddefddbbbb87d3b24c7117528f"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Orderable.html#gaf9a073eafebbe514fb19dff82318f198" title="Returns a Logical representing whether x is greater than y.">hana::greater</a></code> <br /></td></tr>
- <tr class="separator:aedd11fddefddbbbb87d3b24c7117528f"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a53817979990da799e659b2576799a79a"><td class="memTemplParams" colspan="2"><a id="a53817979990da799e659b2576799a79a"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:a53817979990da799e659b2576799a79a"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a53817979990da799e659b2576799a79a">operator<=</a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:a53817979990da799e659b2576799a79a"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Orderable.html#ga9917dd82beb67151bf5657245d37b851" title="Returns a Logical representing whether x is less than or equal to y.">hana::less_equal</a></code> <br /></td></tr>
- <tr class="separator:a53817979990da799e659b2576799a79a"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:aa3f0436b623de5208767751e1e9f7e59"><td class="memTemplParams" colspan="2"><a id="aa3f0436b623de5208767751e1e9f7e59"></a>
- template<typename X , typename Y > </td></tr>
- <tr class="memitem:aa3f0436b623de5208767751e1e9f7e59"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#aa3f0436b623de5208767751e1e9f7e59">operator>=</a> (X &&x, Y &&y)</td></tr>
- <tr class="memdesc:aa3f0436b623de5208767751e1e9f7e59"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="group__group-Orderable.html#ga6023631e7d0a01e16dc3fa4221fbd703" title="Returns a Logical representing whether x is greater than or equal to y.">hana::greater_equal</a></code> <br /></td></tr>
- <tr class="separator:aa3f0436b623de5208767751e1e9f7e59"><td class="memSeparator" colspan="2"> </td></tr>
- </table><table class="memberdecls">
- <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
- Public Member Functions</h2></td></tr>
- <tr class="memitem:aefbd278cf7bb9e921707d6d827014bcb"><td class="memItemLeft" align="right" valign="top"><a id="aefbd278cf7bb9e921707d6d827014bcb"></a>
- constexpr </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#aefbd278cf7bb9e921707d6d827014bcb">optional</a> ()=default</td></tr>
- <tr class="memdesc:aefbd278cf7bb9e921707d6d827014bcb"><td class="mdescLeft"> </td><td class="mdescRight">Default-construct an <code>optional</code>. Only exists if the optional contains a value, and if that value is DefaultConstructible. <br /></td></tr>
- <tr class="separator:aefbd278cf7bb9e921707d6d827014bcb"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a9074406adb54a6a848ba482895c51d1f"><td class="memItemLeft" align="right" valign="top"><a id="a9074406adb54a6a848ba482895c51d1f"></a>
-  </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a9074406adb54a6a848ba482895c51d1f">optional</a> (<a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> const &)=default</td></tr>
- <tr class="memdesc:a9074406adb54a6a848ba482895c51d1f"><td class="mdescLeft"> </td><td class="mdescRight">Copy-construct an <code>optional</code>. An empty optional may only be copy-constructed from another empty <code>optional</code>, and an <code>optional</code> with a value may only be copy-constructed from another <code>optional</code> with a value. Furthermore, this constructor only exists if the value held in the <code>optional</code> is CopyConstructible. <br /></td></tr>
- <tr class="separator:a9074406adb54a6a848ba482895c51d1f"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:ac46a23f0ada20175c4c9a58af3d15753"><td class="memItemLeft" align="right" valign="top"><a id="ac46a23f0ada20175c4c9a58af3d15753"></a>
-  </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#ac46a23f0ada20175c4c9a58af3d15753">optional</a> (<a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> &&)=default</td></tr>
- <tr class="memdesc:ac46a23f0ada20175c4c9a58af3d15753"><td class="mdescLeft"> </td><td class="mdescRight">Move-construct an <code>optional</code>. An empty optional may only be move-constructed from another empty <code>optional</code>, and an <code>optional</code> with a value may only be move-constructed from another <code>optional</code> with a value. Furthermore, this constructor only exists if the value held in the <code>optional</code> is MoveConstructible. <br /></td></tr>
- <tr class="separator:ac46a23f0ada20175c4c9a58af3d15753"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a2b04ee87c0ac58621edf3ad5476a2949"><td class="memItemLeft" align="right" valign="top"><a id="a2b04ee87c0ac58621edf3ad5476a2949"></a>
- constexpr </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a2b04ee87c0ac58621edf3ad5476a2949">optional</a> (T const &t)</td></tr>
- <tr class="memdesc:a2b04ee87c0ac58621edf3ad5476a2949"><td class="mdescLeft"> </td><td class="mdescRight">Construct an <code>optional</code> holding a value of type <code>T</code> from another object of type <code>T</code>. The value is copy-constructed. <br /></td></tr>
- <tr class="separator:a2b04ee87c0ac58621edf3ad5476a2949"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:adf824827b5d6f8c87d23b9526b9f35d2"><td class="memItemLeft" align="right" valign="top"><a id="adf824827b5d6f8c87d23b9526b9f35d2"></a>
- constexpr </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#adf824827b5d6f8c87d23b9526b9f35d2">optional</a> (T &&t)</td></tr>
- <tr class="memdesc:adf824827b5d6f8c87d23b9526b9f35d2"><td class="mdescLeft"> </td><td class="mdescRight">Construct an <code>optional</code> holding a value of type <code>T</code> from another object of type <code>T</code>. The value is move-constructed. <br /></td></tr>
- <tr class="separator:adf824827b5d6f8c87d23b9526b9f35d2"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:abefc885243f38c66c52fdada3588f951"><td class="memItemLeft" align="right" valign="top"><a id="abefc885243f38c66c52fdada3588f951"></a>
- constexpr <a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#abefc885243f38c66c52fdada3588f951">operator=</a> (<a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> const &)=default</td></tr>
- <tr class="memdesc:abefc885243f38c66c52fdada3588f951"><td class="mdescLeft"> </td><td class="mdescRight">Copy-assign an <code>optional</code>. An empty optional may only be copy-assigned from another empty <code>optional</code>, and an <code>optional</code> with a value may only be copy-assigned from another <code>optional</code> with a value. Furthermore, this assignment operator only exists if the value held in the <code>optional</code> is CopyAssignable. <br /></td></tr>
- <tr class="separator:abefc885243f38c66c52fdada3588f951"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a52057c5da4b9aee49ee15a167459fc9a"><td class="memItemLeft" align="right" valign="top"><a id="a52057c5da4b9aee49ee15a167459fc9a"></a>
- constexpr <a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> & </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a52057c5da4b9aee49ee15a167459fc9a">operator=</a> (<a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> &&)=default</td></tr>
- <tr class="memdesc:a52057c5da4b9aee49ee15a167459fc9a"><td class="mdescLeft"> </td><td class="mdescRight">Move-assign an <code>optional</code>. An empty optional may only be move-assigned from another empty <code>optional</code>, and an <code>optional</code> with a value may only be move-assigned from another <code>optional</code> with a value. Furthermore, this assignment operator only exists if the value held in the <code>optional</code> is MoveAssignable. <br /></td></tr>
- <tr class="separator:a52057c5da4b9aee49ee15a167459fc9a"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a6eeef1512294d408857805eb3a790230"><td class="memItemLeft" align="right" valign="top">constexpr T * </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a6eeef1512294d408857805eb3a790230">operator-></a> ()</td></tr>
- <tr class="memdesc:a6eeef1512294d408857805eb3a790230"><td class="mdescLeft"> </td><td class="mdescRight">Returns a pointer to the contained value, or a <code>nullptr</code> if the <code>optional</code> is empty. <a href="#a6eeef1512294d408857805eb3a790230">More...</a><br /></td></tr>
- <tr class="separator:a6eeef1512294d408857805eb3a790230"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:acdcf71b43d4e27d5efbf0ad875d0be58"><td class="memItemLeft" align="right" valign="top">constexpr T & </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58">value</a> ()</td></tr>
- <tr class="memdesc:acdcf71b43d4e27d5efbf0ad875d0be58"><td class="mdescLeft"> </td><td class="mdescRight">Extract the content of an <code>optional</code>, or fail at compile-time. <a href="#acdcf71b43d4e27d5efbf0ad875d0be58">More...</a><br /></td></tr>
- <tr class="separator:acdcf71b43d4e27d5efbf0ad875d0be58"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a237b2147dd9b72bb2dfa4a268056e4c2"><td class="memItemLeft" align="right" valign="top">constexpr T & </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a237b2147dd9b72bb2dfa4a268056e4c2">operator *</a> ()</td></tr>
- <tr class="memdesc:a237b2147dd9b72bb2dfa4a268056e4c2"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code><a class="el" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58" title="Extract the content of an optional, or fail at compile-time.">value()</a></code>, provided for convenience. <a href="#a237b2147dd9b72bb2dfa4a268056e4c2">More...</a><br /></td></tr>
- <tr class="separator:a237b2147dd9b72bb2dfa4a268056e4c2"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a1f511267d94c178e4ef955da60f0888d"><td class="memTemplParams" colspan="2">template<typename U > </td></tr>
- <tr class="memitem:a1f511267d94c178e4ef955da60f0888d"><td class="memTemplItemLeft" align="right" valign="top">decltype(auto) constexpr </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1optional.html#a1f511267d94c178e4ef955da60f0888d">value_or</a> (U &&<a class="el" href="structboost_1_1hana_1_1default__.html">default_</a>)</td></tr>
- <tr class="memdesc:a1f511267d94c178e4ef955da60f0888d"><td class="mdescLeft"> </td><td class="mdescRight">Return the contents of an <code>optional</code>, with a fallback result. <a href="#a1f511267d94c178e4ef955da60f0888d">More...</a><br /></td></tr>
- <tr class="separator:a1f511267d94c178e4ef955da60f0888d"><td class="memSeparator" colspan="2"> </td></tr>
- </table>
- <h2 class="groupheader">Associated functions</h2>
- <a id="a76a84854b3051af000e698157d63a6a8"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a76a84854b3051af000e698157d63a6a8">◆ </a></span>make< optional_tag ></h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <div class="memtemplate">
- template<> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a>< <a class="el" href="structboost_1_1hana_1_1optional__tag.html">optional_tag</a> ></td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <b>Initial value:</b><div class="fragment"><div class="line">= []([<span class="keyword">auto</span>&& x]) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="structboost_1_1hana_1_1optional.html#aefbd278cf7bb9e921707d6d827014bcb">optional</a><std::decay<decltype(x)>::type>{forwarded(x)};</div><div class="line"> }</div></div><!-- fragment -->
- <p>Create an optional value. </p>
- <p>Specifically, <code>make<<a class="el" href="structboost_1_1hana_1_1optional__tag.html" title="Tag representing a hana::optional.">optional_tag</a>>()</code> is equivalent to <code>nothing</code>, and <code>make<<a class="el" href="structboost_1_1hana_1_1optional__tag.html" title="Tag representing a hana::optional.">optional_tag</a>>(x)</code> is equivalent to <code>just(x)</code>. This is provided for consistency with the other <code>make<...></code> functions.</p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="core_2make_8hpp.html">boost/hana/core/make.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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"> constexpr <span class="keyword">auto</span> x = hana::make<hana::optional_tag>();</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(x == hana::make_optional());</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_nothing(x));</div><div class="line"></div><div class="line"> constexpr <span class="keyword">auto</span> just_x = hana::make<hana::optional_tag>(<span class="charliteral">'x'</span>);</div><div class="line"> static_assert(just_x == hana::make_optional(<span class="charliteral">'x'</span>), <span class="stringliteral">""</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_just(just_x));</div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="af1105a435d6435a2437cb5dc162ba463"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#af1105a435d6435a2437cb5dc162ba463">◆ </a></span>make_optional</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto make_optional = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">make</a><<a class="el" href="structboost_1_1hana_1_1optional__tag.html">optional_tag</a>></td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>Alias to <code>make<<a class="el" href="structboost_1_1hana_1_1optional__tag.html" title="Tag representing a hana::optional.">optional_tag</a>></code>; provided for convenience. </p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="core_2make_8hpp.html">boost/hana/core/make.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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"> constexpr <span class="keyword">auto</span> x = hana::make<hana::optional_tag>();</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(x == hana::make_optional());</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_nothing(x));</div><div class="line"></div><div class="line"> constexpr <span class="keyword">auto</span> just_x = hana::make<hana::optional_tag>(<span class="charliteral">'x'</span>);</div><div class="line"> static_assert(just_x == hana::make_optional(<span class="charliteral">'x'</span>), <span class="stringliteral">""</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_just(just_x));</div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a8ad818d6df7379b0adefa45d2ac844d0"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a8ad818d6df7379b0adefa45d2ac844d0">◆ </a></span>just</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto just</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&& x) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="structboost_1_1hana_1_1optional.html#aefbd278cf7bb9e921707d6d827014bcb">optional</a><std::decay<decltype(x)>::type>{forwarded(x)};</div><div class="line"> }</div></div><!-- fragment -->
- <p>Create an optional value containing <code>x</code>. </p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> just_x = hana::just(<span class="charliteral">'x'</span>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_just(just_x));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a0c315287473aa87fe5ccd9d8a1c10186"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a0c315287473aa87fe5ccd9d8a1c10186">◆ </a></span>nothing</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr <a class="el" href="structboost_1_1hana_1_1optional.html">optional</a> nothing {}</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>An empty optional value. </p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> x = hana::nothing;</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::is_nothing(x));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a6529e11cb228e99a05e81071752807d5"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a6529e11cb228e99a05e81071752807d5">◆ </a></span>maybe</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto maybe</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&& default_, <span class="keyword">auto</span>&& f, <span class="keyword">auto</span>&& m) -> decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">if</span> (m is a <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x)) {</div><div class="line"> <span class="keywordflow">return</span> forwarded(f)(forwarded(x));</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> <span class="keywordflow">return</span> forwarded(default_);</div><div class="line"> }</div><div class="line"> }</div></div><!-- fragment -->
- <p>Apply a function to the contents of an optional, with a fallback result. </p>
- <p>Specifically, <code>maybe</code> takes a default value, a function and an optional value. If the optional value is <code>nothing</code>, the default value is returned. Otherwise, the function is applied to the content of the <code>just</code>.</p>
- <dl class="params"><dt>Parameters</dt><dd>
- <table class="params">
- <tr><td class="paramname"><a class="el" href="structboost_1_1hana_1_1default__.html" title="Mark a tag-dispatched method implementation as a default implementation.">default_</a></td><td>A default value returned if <code>m</code> is <code>nothing</code>.</td></tr>
- <tr><td class="paramname">f</td><td>A function called as <code>f(x)</code> if and only if <code>m</code> is an optional value of the form <code>just(x)</code>. In that case, the result returend by <code>maybe</code> is the result of <code>f</code>.</td></tr>
- <tr><td class="paramname">m</td><td>An optional value.</td></tr>
- </table>
- </dd>
- </dl>
- <h2>Example </h2>
- <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 <<a class="code" href="placeholder_8hpp.html">boost/hana/functional/placeholder.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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::maybe(<span class="charliteral">'x'</span>, <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1, hana::just(1)) == 2, <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::maybe(<span class="charliteral">'x'</span>, <a class="code" href="group__group-functional.html#gaefe9fd152cba94be71c2b5b9de689d23">hana::_</a> + 1, hana::nothing) == <span class="charliteral">'x'</span>, <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="aa4c8c0b1ef3d8206974734b93646c9fd"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#aa4c8c0b1ef3d8206974734b93646c9fd">◆ </a></span>sfinae</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">auto sfinae</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <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> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&& ...x) {</div><div class="line"> <span class="keywordflow">if</span> (decltype(forwarded(f)(forwarded(x)...)) is well-formed)</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(forwarded(f)(forwarded(x)...));</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>;</div><div class="line"> };</div><div class="line"> }</div></div><!-- fragment -->
- <p>Calls a function if the call expression is well-formed. </p>
- <p>Given a function <code>f</code>, <code>sfinae</code> returns a new function applying <code>f</code> to its arguments and returning <code>just</code> the result if the call is well-formed, and <code>nothing</code> otherwise. In other words, <code>sfinae(f)(x...)</code> is <code>just(f(x...))</code> if that expression is well-formed, and <code>nothing</code> otherwise. Note, however, that it is possible for an expression <code>f(x...)</code> to be well-formed as far as SFINAE is concerned, but trying to actually compile <code>f(x...)</code> still fails. In this case, <code>sfinae</code> won't be able to detect it and a hard failure is likely to happen.</p>
- <dl class="section note"><dt>Note</dt><dd>The function given to <code>sfinae</code> must not return <code>void</code>, since <code>just(void)</code> does not make sense. A compilation error is triggered if the function returns void.</dd></dl>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="config_8hpp.html">boost/hana/config.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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> incr = [](<span class="keyword">auto</span> x) -> decltype(x + 1) {</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>(hana::sfinae(incr)(1) == hana::just(2));</div><div class="line"></div><div class="line"> <span class="keyword">struct </span>invalid { };</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::sfinae(incr)(invalid{}) == hana::nothing);</div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a1047a69893a62cd36eb0d2934f85e0e7"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a1047a69893a62cd36eb0d2934f85e0e7">◆ </a></span>is_just</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto is_just</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span> <span class="keyword">const</span>& m) {</div><div class="line"> <span class="keywordflow">return</span> m is a <a class="code" href="structboost_1_1hana_1_1optional.html#a8ad818d6df7379b0adefa45d2ac844d0">just</a>(x);</div><div class="line"> }</div></div><!-- fragment -->
- <p>Return whether an <code>optional</code> contains a value. </p>
- <p>Specifically, returns a compile-time true-valued <code>Logical</code> if <code>m</code> is of the form <code>just(x)</code> for some <code>x</code>, and a false-valued one otherwise.</p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="not_8hpp.html">boost/hana/not.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>( hana::is_just(hana::just(<span class="charliteral">'x'</span>)));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>( hana::is_just(hana::just(hana::nothing)));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(!hana::is_just(hana::nothing));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a4eb266d123883c23853f7731a6c5953f"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a4eb266d123883c23853f7731a6c5953f">◆ </a></span>is_nothing</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="mlabels">
- <tr>
- <td class="mlabels-left">
- <table class="memname">
- <tr>
- <td class="memname">constexpr auto is_nothing</td>
- </tr>
- </table>
- </td>
- <td class="mlabels-right">
- <span class="mlabels"><span class="mlabel">related</span></span> </td>
- </tr>
- </table>
- </div><div class="memdoc">
- <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span> <span class="keyword">const</span>& m) {</div><div class="line"> <span class="keywordflow">return</span> m is a <a class="code" href="structboost_1_1hana_1_1optional.html#a0c315287473aa87fe5ccd9d8a1c10186">nothing</a>;</div><div class="line"> }</div></div><!-- fragment -->
- <p>Return whether an <code>optional</code> is empty. </p>
- <p>Specifically, returns a compile-time true-valued <code>Logical</code> if <code>m</code> is a <code>nothing</code>, and a false-valued one otherwise.</p>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="not_8hpp.html">boost/hana/not.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>( hana::is_nothing(hana::nothing));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(!hana::is_nothing(hana::just(<span class="charliteral">'x'</span>)));</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(!hana::is_nothing(hana::just(hana::nothing)));</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <h2 class="groupheader">Member Function Documentation</h2>
- <a id="a6eeef1512294d408857805eb3a790230"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a6eeef1512294d408857805eb3a790230">◆ </a></span>operator->()</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="memname">
- <tr>
- <td class="memname">constexpr T* <a class="el" href="structboost_1_1hana_1_1optional.html">boost::hana::optional</a>< T >::operator-> </td>
- <td>(</td>
- <td class="paramname"></td><td>)</td>
- <td></td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>Returns a pointer to the contained value, or a <code>nullptr</code> if the <code>optional</code> is empty. </p>
- <dl class="section note"><dt>Note</dt><dd>Overloads of this method are provided for both the <code>const</code> and the non-<code>const</code> cases.</dd></dl>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <string></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"> static_assert(hana::just(<span class="charliteral">'x'</span>).<a class="code" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58">value</a>() == <span class="charliteral">'x'</span>, <span class="stringliteral">""</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(*hana::just(hana::type_c<int>) == hana::type_c<int>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::just(std::string{<span class="stringliteral">"abcd"</span>})-><a class="code" href="group__group-Foldable.html#ga8ec3ac9a6f5014db943f61ebc9e1e36e">size</a>() == 4);</div><div class="line"></div><div class="line"> <span class="comment">// hana::nothing.value(); // compile-time error</span></div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="acdcf71b43d4e27d5efbf0ad875d0be58"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#acdcf71b43d4e27d5efbf0ad875d0be58">◆ </a></span>value()</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="memname">
- <tr>
- <td class="memname">constexpr T& <a class="el" href="structboost_1_1hana_1_1optional.html">boost::hana::optional</a>< T >::value </td>
- <td>(</td>
- <td class="paramname"></td><td>)</td>
- <td></td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>Extract the content of an <code>optional</code>, or fail at compile-time. </p>
- <p>If <code>*this</code> contains a value, that value is returned. Otherwise, a static assertion is triggered.</p>
- <dl class="section note"><dt>Note</dt><dd>Overloads of this method are provided for the cases where <code>*this</code> is a reference, a rvalue-reference and their <code>const</code> counterparts.</dd></dl>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <string></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"> static_assert(hana::just(<span class="charliteral">'x'</span>).<a class="code" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58">value</a>() == <span class="charliteral">'x'</span>, <span class="stringliteral">""</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(*hana::just(hana::type_c<int>) == hana::type_c<int>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::just(std::string{<span class="stringliteral">"abcd"</span>})-><a class="code" href="group__group-Foldable.html#ga8ec3ac9a6f5014db943f61ebc9e1e36e">size</a>() == 4);</div><div class="line"></div><div class="line"> <span class="comment">// hana::nothing.value(); // compile-time error</span></div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a237b2147dd9b72bb2dfa4a268056e4c2"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a237b2147dd9b72bb2dfa4a268056e4c2">◆ </a></span>operator *()</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <table class="memname">
- <tr>
- <td class="memname">constexpr T& <a class="el" href="structboost_1_1hana_1_1optional.html">boost::hana::optional</a>< T >::operator * </td>
- <td>(</td>
- <td class="paramname"></td><td>)</td>
- <td></td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>Equivalent to <code><a class="el" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58" title="Extract the content of an optional, or fail at compile-time.">value()</a></code>, provided for convenience. </p>
- <dl class="section note"><dt>Note</dt><dd>Overloads of this method are provided for the cases where <code>*this</code> is a reference, a rvalue-reference and their <code>const</code> counterparts.</dd></dl>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="type_8hpp.html">boost/hana/type.hpp</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <string></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"> static_assert(hana::just(<span class="charliteral">'x'</span>).<a class="code" href="structboost_1_1hana_1_1optional.html#acdcf71b43d4e27d5efbf0ad875d0be58">value</a>() == <span class="charliteral">'x'</span>, <span class="stringliteral">""</span>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(*hana::just(hana::type_c<int>) == hana::type_c<int>);</div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(hana::just(std::string{<span class="stringliteral">"abcd"</span>})-><a class="code" href="group__group-Foldable.html#ga8ec3ac9a6f5014db943f61ebc9e1e36e">size</a>() == 4);</div><div class="line"></div><div class="line"> <span class="comment">// hana::nothing.value(); // compile-time error</span></div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a1f511267d94c178e4ef955da60f0888d"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a1f511267d94c178e4ef955da60f0888d">◆ </a></span>value_or()</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename ... T> </div>
- <div class="memtemplate">
- template<typename U > </div>
- <table class="memname">
- <tr>
- <td class="memname">decltype(auto) constexpr <a class="el" href="structboost_1_1hana_1_1optional.html">boost::hana::optional</a>< T >::value_or </td>
- <td>(</td>
- <td class="paramtype">U && </td>
- <td class="paramname"><em>default_</em></td><td>)</td>
- <td></td>
- </tr>
- </table>
- </div><div class="memdoc">
- <p>Return the contents of an <code>optional</code>, with a fallback result. </p>
- <p>If <code>*this</code> contains a value, that value is returned. Otherwise, the default value provided is returned.</p>
- <dl class="section note"><dt>Note</dt><dd>Overloads of this method are provided for the cases where <code>*this</code> is a reference, a rvalue-reference and their <code>const</code> counterparts.</dd></dl>
- <dl class="params"><dt>Parameters</dt><dd>
- <table class="params">
- <tr><td class="paramname"><a class="el" href="structboost_1_1hana_1_1default__.html" title="Mark a tag-dispatched method implementation as a default implementation.">default_</a></td><td>The default value to return if <code>*this</code> does not contain a value.</td></tr>
- </table>
- </dd>
- </dl>
- <h2>Example </h2>
- <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 <<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="optional_8hpp.html">boost/hana/optional.hpp</a>></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::just(1).<a class="code" href="structboost_1_1hana_1_1optional.html#a1f511267d94c178e4ef955da60f0888d">value_or</a>(<span class="charliteral">'x'</span>) == 1, <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::nothing.<a class="code" href="structboost_1_1hana_1_1optional.html#a1f511267d94c178e4ef955da60f0888d">value_or</a>(<span class="charliteral">'x'</span>) == <span class="charliteral">'x'</span>, <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- </div><!-- contents -->
- </div><!-- doc-content -->
- <!--
- Copyright Louis Dionne 2013-2017
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
- -->
- <!-- boost-no-inspect -->
- <!-- HTML footer for doxygen 1.8.9.1-->
- <!-- start footer part -->
- <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
- <ul>
- <li class="navelem"><b>boost</b></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_1optional.html">optional</a></li>
- </ul>
- </div>
- </body>
- </html>
|