123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- <!--
- 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::type< 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_1type.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_1type-members.html">List of all members</a> </div>
- <div class="headertitle">
- <div class="title">boost::hana::type< 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::type< T ></h3>
- <p>C++ type in value-level representation. </p>
- <p>A <code>type</code> is a special kind of object representing a C++ type like <code>int</code>, <code>void</code>, <code>std::vector<float></code> or anything else you can imagine.</p>
- <p>This page explains how <code>type</code>s work at a low level. To gain intuition about type-level metaprogramming in Hana, you should read the <a class="el" href="index.html#tutorial-type">tutorial section</a> on type-level computations.</p>
- <dl class="section note"><dt>Note</dt><dd>For subtle reasons, the actual representation of <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> is implementation-defined. In particular, <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> may be a dependent type, so one should not attempt to do pattern matching on it. However, one can assume that <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> <em>inherits</em> from <code><a class="el" href="structboost_1_1hana_1_1basic__type.html" title="Base class of hana::type; used for pattern-matching.">hana::basic_type</a></code>, which can be useful when declaring overloaded functions: <div class="fragment"><div class="line"><span class="keyword">template</span> <<span class="keyword">typename</span> T></div><div class="line"><span class="keywordtype">void</span> f(hana::basic_type<T>) {</div><div class="line"> <span class="comment">// do something with T</span></div><div class="line">}</div></div><!-- fragment --> The full story is that <a href="http://en.cppreference.com/w/cpp/language/adl">ADL</a> causes template arguments to be instantiated. Hence, if <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> were defined naively, expressions like <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a><T>{} == <a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a><U>{}</code> would cause both <code>T</code> and <code>U</code> to be instantiated. This is usually not a problem, except when <code>T</code> or <code>U</code> should not be instantiated. To avoid these instantiations, <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> is implemented using some cleverness, and that is why the representation is implementation-defined. When that behavior is not required, <code><a class="el" href="structboost_1_1hana_1_1basic__type.html" title="Base class of hana::type; used for pattern-matching.">hana::basic_type</a></code> can be used instead.</dd></dl>
- <p><a class="anchor" id="type_lvalues_and_rvalues"></a></p><h2>Lvalues and rvalues </h2>
- <p>When storing <code>type</code>s in heterogeneous containers, some algorithms will return references to those objects. Since we are primarily interested in accessing their nested <code>::type</code>, receiving a reference is undesirable; we would end up trying to fetch the nested <code>::type</code> inside a reference type, which is a compilation error: </p><div class="fragment"><div class="line"><span class="keyword">auto</span> ts = make_tuple(type_c<int>, type_c<char>);</div><div class="line"><span class="keyword">using</span> T = decltype(ts[0_c])::type; <span class="comment">// error: 'ts[0_c]' is a reference!</span></div></div><!-- fragment --><p>For this reason, <code>type</code>s provide an overload of the unary <code>+</code> operator that can be used to turn a lvalue into a rvalue. So when using a result which might be a reference to a <code>type</code> object, one can use <code>+</code> to make sure a rvalue is obtained before fetching its nested <code>::type</code>: </p><div class="fragment"><div class="line"><span class="keyword">auto</span> ts = make_tuple(type_c<int>, type_c<char>);</div><div class="line"><span class="keyword">using</span> T = decltype(+ts[0_c])::type; <span class="comment">// ok: '+ts[0_c]' is an rvalue</span></div></div><!-- fragment --><h2>Modeled concepts </h2>
- <ol type="1">
- <li><code>Comparable</code><br />
- Two types are equal if and only if they represent the same C++ type. Hence, equality is equivalent to the <code>std::is_same</code> type trait. <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="type_8hpp.html">boost/hana/type.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">struct </span>T;</div><div class="line"><span class="keyword">struct </span>U;</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::type_c<T> == hana::type_c<T>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::type_c<T> != hana::type_c<U>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --></li>
- <li><code>Hashable</code><br />
- The hash of a type is just that type itself. In other words, <code>hash</code> is the identity function on <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code>s. <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="hash_8hpp.html">boost/hana/hash.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"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// `hana::hash` is the identity on `hana::type`s.</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-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(</div><div class="line"> <a class="code" href="group__group-Hashable.html#ga6e906f44f47b210615491385e5c8a7b5">hana::hash</a>(hana::type_c<int>),</div><div class="line"> hana::type_c<int></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-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(</div><div class="line"> <a class="code" href="group__group-Hashable.html#ga6e906f44f47b210615491385e5c8a7b5">hana::hash</a>(hana::type_c<void>),</div><div class="line"> hana::type_c<void></div><div class="line">));</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:ae35139e732c4b75e91061513cf445628"><td class="memTemplParams" colspan="2">template<typename T > </td></tr>
- <tr class="memitem:ae35139e732c4b75e91061513cf445628"><td class="memTemplItemLeft" align="right" valign="top">constexpr <a class="el" href="structboost_1_1hana_1_1type.html">type</a>< T > </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#ae35139e732c4b75e91061513cf445628">type_c</a> {}</td></tr>
- <tr class="memdesc:ae35139e732c4b75e91061513cf445628"><td class="mdescLeft"> </td><td class="mdescRight">Creates an object representing the C++ type <code>T</code>. <a href="#ae35139e732c4b75e91061513cf445628">More...</a><br /></td></tr>
- <tr class="separator:ae35139e732c4b75e91061513cf445628"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a7d68ff2275cbb295556d83598f04e39a"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a7d68ff2275cbb295556d83598f04e39a">decltype_</a> = see documentation</td></tr>
- <tr class="memdesc:a7d68ff2275cbb295556d83598f04e39a"><td class="mdescLeft"> </td><td class="mdescRight"><code>decltype</code> keyword, lifted to Hana. <a href="#a7d68ff2275cbb295556d83598f04e39a">More...</a><br /></td></tr>
- <tr class="separator:a7d68ff2275cbb295556d83598f04e39a"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a0ade557ac4240552c92bf47c7e04dfd4"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a0ade557ac4240552c92bf47c7e04dfd4">typeid_</a> = see documentation</td></tr>
- <tr class="memdesc:a0ade557ac4240552c92bf47c7e04dfd4"><td class="mdescLeft"> </td><td class="mdescRight">Returns a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> representing the type of a given object. <a href="#a0ade557ac4240552c92bf47c7e04dfd4">More...</a><br /></td></tr>
- <tr class="separator:a0ade557ac4240552c92bf47c7e04dfd4"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a66f97c1903dcb6f227b29f3e35e68a56"><td class="memTemplParams" colspan="2">template<> </td></tr>
- <tr class="memitem:a66f97c1903dcb6f227b29f3e35e68a56"><td class="memTemplItemLeft" align="right" valign="top">constexpr auto </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a66f97c1903dcb6f227b29f3e35e68a56">make< type_tag ></a> = hana::decltype_</td></tr>
- <tr class="memdesc:a66f97c1903dcb6f227b29f3e35e68a56"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code>decltype_</code>, provided for convenience. <a href="#a66f97c1903dcb6f227b29f3e35e68a56">More...</a><br /></td></tr>
- <tr class="separator:a66f97c1903dcb6f227b29f3e35e68a56"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a0c0e00c0ffe63703f3a04960d13c7b1c"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a0c0e00c0ffe63703f3a04960d13c7b1c">make_type</a> = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">hana::make</a><<a class="el" href="structboost_1_1hana_1_1type__tag.html">type_tag</a>></td></tr>
- <tr class="memdesc:a0c0e00c0ffe63703f3a04960d13c7b1c"><td class="mdescLeft"> </td><td class="mdescRight">Equivalent to <code>make<<a class="el" href="structboost_1_1hana_1_1type__tag.html" title="Tag representing hana::type.">type_tag</a>></code>, provided for convenience. <a href="#a0c0e00c0ffe63703f3a04960d13c7b1c">More...</a><br /></td></tr>
- <tr class="separator:a0c0e00c0ffe63703f3a04960d13c7b1c"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a26b702b280ca02f118affaaca9112a8c"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a26b702b280ca02f118affaaca9112a8c">sizeof_</a></td></tr>
- <tr class="memdesc:a26b702b280ca02f118affaaca9112a8c"><td class="mdescLeft"> </td><td class="mdescRight"><code>sizeof</code> keyword, lifted to Hana. <a href="#a26b702b280ca02f118affaaca9112a8c">More...</a><br /></td></tr>
- <tr class="separator:a26b702b280ca02f118affaaca9112a8c"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a6fd9ac456f4b5574dcb16384dbb85736"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a6fd9ac456f4b5574dcb16384dbb85736">alignof_</a></td></tr>
- <tr class="memdesc:a6fd9ac456f4b5574dcb16384dbb85736"><td class="mdescLeft"> </td><td class="mdescRight"><code>alignof</code> keyword, lifted to Hana. <a href="#a6fd9ac456f4b5574dcb16384dbb85736">More...</a><br /></td></tr>
- <tr class="separator:a6fd9ac456f4b5574dcb16384dbb85736"><td class="memSeparator" colspan="2"> </td></tr>
- <tr class="memitem:a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b"><td class="memItemLeft" align="right" valign="top">constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b">is_valid</a></td></tr>
- <tr class="memdesc:a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b"><td class="mdescLeft"> </td><td class="mdescRight">Checks whether a SFINAE-friendly expression is valid. <a href="#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b">More...</a><br /></td></tr>
- <tr class="separator:a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b"><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: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_1type.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_1type.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>
- </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:a228c1b24d16b2c765c816f816a09337c"><td class="memItemLeft" align="right" valign="top"><a id="a228c1b24d16b2c765c816f816a09337c"></a>
- constexpr auto </td><td class="memItemRight" valign="bottom"><a class="el" href="structboost_1_1hana_1_1type.html#a228c1b24d16b2c765c816f816a09337c">operator+</a> () const</td></tr>
- <tr class="memdesc:a228c1b24d16b2c765c816f816a09337c"><td class="mdescLeft"> </td><td class="mdescRight">Returns rvalue of self. See <a class="el" href="structboost_1_1hana_1_1type.html#type_lvalues_and_rvalues">description</a>. <br /></td></tr>
- <tr class="separator:a228c1b24d16b2c765c816f816a09337c"><td class="memSeparator" colspan="2"> </td></tr>
- </table>
- <h2 class="groupheader">Associated functions</h2>
- <a id="ae35139e732c4b75e91061513cf445628"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#ae35139e732c4b75e91061513cf445628">◆ </a></span>type_c</h2>
- <div class="memitem">
- <div class="memproto">
- <div class="memtemplate">
- template<typename T > </div>
- <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_1type.html">type</a><T> type_c {}</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>Creates an object representing the C++ type <code>T</code>. </p>
- </div>
- </div>
- <a id="a7d68ff2275cbb295556d83598f04e39a"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a7d68ff2275cbb295556d83598f04e39a">◆ </a></span>decltype_</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 decltype_ = see documentation</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><code>decltype</code> keyword, lifted to Hana. </p>
- <dl class="deprecated"><dt><b><a class="el" href="deprecated.html#_deprecated000001">Deprecated:</a></b></dt><dd>The semantics of <code>decltype_</code> can be confusing, and <code>hana::typeid_</code> should be preferred instead. <code>decltype_</code> may be removed in the next major version of the library.</dd></dl>
- <p><code>decltype_</code> is somewhat equivalent to <code>decltype</code> in that it returns the type of an object, except it returns it as a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> which is a first-class citizen of Hana instead of a raw C++ type. Specifically, given an object <code>x</code>, <code>decltype_</code> satisfies </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a7d68ff2275cbb295556d83598f04e39a">decltype_</a>(x) == <a class="code" href="structboost_1_1hana_1_1type.html#ae35139e732c4b75e91061513cf445628">type_c</a><decltype(x) with references stripped></div></div><!-- fragment --><p>As you can see, <code>decltype_</code> will strip any reference from the object's actual type. The reason for doing so is explained below. However, any <code>cv</code>-qualifiers will be retained. Also, when given a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code>, <code>decltype_</code> is just the identity function. Hence, for any C++ type <code>T</code>, </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a7d68ff2275cbb295556d83598f04e39a">decltype_</a>(type_c<T>) == type_c<T></div></div><!-- fragment --><p>In conjunction with the way <code>metafunction</code> & al. are specified, this behavior makes it easier to interact with both types and values at the same time. However, it does make it impossible to create a <code>type</code> containing another <code>type</code> with <code>decltype_</code>. In other words, it is not possible to create a <code>type_c<decltype(type_c<T>)></code> with this utility, because <code>decltype_(type_c<T>)</code> would be just <code>type_c<T></code> instead of <code>type_c<decltype(type_c<T>)></code>. This use case is assumed to be rare and a hand-coded function can be used if this is needed.</p>
- <h3>Rationale for stripping the references</h3>
- <p>The rules for template argument deduction are such that a perfect solution that always matches <code>decltype</code> is impossible. Hence, we have to settle on a solution that's good and and consistent enough for our needs. One case where matching <code>decltype</code>'s behavior is impossible is when the argument is a plain, unparenthesized variable or function parameter. In that case, <code>decltype_</code>'s argument will be deduced as a reference to that variable, but <code>decltype</code> would have given us the actual type of that variable, without references. Also, given the current definition of <code>metafunction</code> & al., it would be mostly useless if <code>decltype_</code> could return a reference, because it is unlikely that <code>F</code> expects a reference in its simplest use case: </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> i = 0;</div><div class="line"><span class="keyword">auto</span> result = metafunction<F>(i);</div></div><!-- fragment --><p>Hence, always discarding references seems to be the least painful solution.</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="equal_8hpp.html">boost/hana/equal.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"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>X { };</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::decltype_(X{}) == hana::type_c<X>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::decltype_(hana::type_c<X>) == hana::type_c<X>);</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::decltype_(1) == hana::type_c<int>);</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> <span class="keyword">const</span>& i = 1;</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::decltype_(i) == hana::type_c<int const>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a0ade557ac4240552c92bf47c7e04dfd4"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a0ade557ac4240552c92bf47c7e04dfd4">◆ </a></span>typeid_</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 typeid_ = see documentation</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>Returns a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> representing the type of a given object. </p>
- <p><code>hana::typeid_</code> is somewhat similar to <code>typeid</code> in that it returns something that represents the type of an object. However, what <code>typeid</code> returns represent the <em>runtime</em> type of the object, while <code>hana::typeid_</code> returns the <em>static</em> type of the object. Specifically, given an object <code>x</code>, <code>typeid_</code> satisfies </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a0ade557ac4240552c92bf47c7e04dfd4">typeid_</a>(x) == <a class="code" href="structboost_1_1hana_1_1type.html#ae35139e732c4b75e91061513cf445628">type_c</a><decltype(x) with ref and cv-qualifiers stripped></div></div><!-- fragment --><p>As you can see, <code>typeid_</code> strips any reference and cv-qualifier from the object's actual type. The reason for doing so is that it faithfully models how the language's <code>typeid</code> behaves with respect to reference and cv-qualifiers, and it also turns out to be the desirable behavior most of the time. Also, when given a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code>, <code>typeid_</code> is just the identity function. Hence, for any C++ type <code>T</code>, </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a0ade557ac4240552c92bf47c7e04dfd4">typeid_</a>(type_c<T>) == type_c<T></div></div><!-- fragment --><p>In conjunction with the way <code>metafunction</code> & al. are specified, this behavior makes it easier to interact with both types and values at the same time. However, it does make it impossible to create a <code>type</code> containing another <code>type</code> using <code>typeid_</code>. This use case is assumed to be rare and a hand-coded function can be used if this is needed.</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="equal_8hpp.html">boost/hana/equal.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="remove__if_8hpp.html">boost/hana/remove_if.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="code" href="tuple_8hpp.html">boost/hana/tuple.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="keyword">struct </span>Cat { std::string name; };</div><div class="line"><span class="keyword">struct </span>Dog { std::string name; };</div><div class="line"><span class="keyword">struct </span>Fish { std::string name; };</div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a27607958295e6da8a0ba602a2db468f1">operator==</a>(Cat <span class="keyword">const</span>& a, Cat <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name == b.name; }</div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a0cae3af55edb3eb05bfa184bda633f7d">operator!=</a>(Cat <span class="keyword">const</span>& a, Cat <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name != b.name; }</div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a27607958295e6da8a0ba602a2db468f1">operator==</a>(Dog <span class="keyword">const</span>& a, Dog <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name == b.name; }</div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a0cae3af55edb3eb05bfa184bda633f7d">operator!=</a>(Dog <span class="keyword">const</span>& a, Dog <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name != b.name; }</div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a27607958295e6da8a0ba602a2db468f1">operator==</a>(Fish <span class="keyword">const</span>& a, Fish <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name == b.name; }</div><div class="line"><span class="keywordtype">bool</span> <a class="code" href="structboost_1_1hana_1_1type.html#a0cae3af55edb3eb05bfa184bda633f7d">operator!=</a>(Fish <span class="keyword">const</span>& a, Fish <span class="keyword">const</span>& b) { <span class="keywordflow">return</span> a.name != b.name; }</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> hana::tuple<Cat, Fish, Dog, Fish> animals{</div><div class="line"> Cat{<span class="stringliteral">"Garfield"</span>}, Fish{<span class="stringliteral">"Jaws"</span>}, Dog{<span class="stringliteral">"Beethoven"</span>}, Fish{<span class="stringliteral">"Nemo"</span>}</div><div class="line"> };</div><div class="line"></div><div class="line"> <span class="keyword">auto</span> mammals = <a class="code" href="group__group-MonadPlus.html#ga9700169a45664d50377c1be9d58accd3">hana::remove_if</a>(animals, [](<span class="keyword">auto</span> <span class="keyword">const</span>& a) {</div><div class="line"> <span class="keywordflow">return</span> hana::typeid_(a) == hana::type<Fish>{};</div><div class="line"> });</div><div class="line"></div><div class="line"> <a class="code" href="group__group-assertions.html#ga4796ae107d58b67e0bbccd5ae6f70101">BOOST_HANA_RUNTIME_CHECK</a>(mammals == hana::make_tuple(Cat{<span class="stringliteral">"Garfield"</span>}, Dog{<span class="stringliteral">"Beethoven"</span>}));</div><div class="line">}</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a66f97c1903dcb6f227b29f3e35e68a56"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a66f97c1903dcb6f227b29f3e35e68a56">◆ </a></span>make< type_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_1type__tag.html">type_tag</a> > = hana::decltype_</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>Equivalent to <code>decltype_</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="type_8hpp.html">boost/hana/type.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">struct </span>X { };</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make<hana::type_tag>(X{}) == hana::type_c<X>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make<hana::type_tag>(hana::type_c<X>) == hana::type_c<X>);</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make_type(X{}) == hana::type_c<X>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make_type(hana::type_c<X>) == hana::type_c<X>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a0c0e00c0ffe63703f3a04960d13c7b1c"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a0c0e00c0ffe63703f3a04960d13c7b1c">◆ </a></span>make_type</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_type = <a class="el" href="group__group-core.html#ga1d92480f0af1029878e773dafa3e2f60">hana::make</a><<a class="el" href="structboost_1_1hana_1_1type__tag.html">type_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>Equivalent to <code>make<<a class="el" href="structboost_1_1hana_1_1type__tag.html" title="Tag representing hana::type.">type_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="type_8hpp.html">boost/hana/type.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">struct </span>X { };</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make<hana::type_tag>(X{}) == hana::type_c<X>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make<hana::type_tag>(hana::type_c<X>) == hana::type_c<X>);</div><div class="line"></div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make_type(X{}) == hana::type_c<X>);</div><div class="line"><a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(hana::make_type(hana::type_c<X>) == hana::type_c<X>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment -->
- </div>
- </div>
- <a id="a26b702b280ca02f118affaaca9112a8c"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a26b702b280ca02f118affaaca9112a8c">◆ </a></span>sizeof_</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 sizeof_</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="keyword">using</span> T = <span class="keyword">typename</span> decltype(hana::decltype_(x))::type;</div><div class="line"> <span class="keywordflow">return</span> hana::size_c<<span class="keyword">sizeof</span>(T)>;</div><div class="line"> }</div></div><!-- fragment -->
- <p><code>sizeof</code> keyword, lifted to Hana. </p>
- <p><code>sizeof_</code> is somewhat equivalent to <code>sizeof</code> in that it returns the size of an expression or type, but it takes an arbitrary expression or a <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code> and returns its size as an <code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">integral_constant</a></code>. Specifically, given an expression <code>expr</code>, <code>sizeof_</code> satisfies </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a26b702b280ca02f118affaaca9112a8c">sizeof_</a>(expr) == <span class="keywordtype">size_t</span><<span class="keyword">sizeof</span>(decltype(expr) with references stripped)></div></div><!-- fragment --><p>However, given a <code>type</code>, <code>sizeof_</code> will simply fetch the size of the C++ type represented by that object. In other words, </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a26b702b280ca02f118affaaca9112a8c">sizeof_</a>(type_c<T>) == <span class="keywordtype">size_t</span><<span class="keyword">sizeof</span>(T)></div></div><!-- fragment --><p>The behavior of <code>sizeof_</code> is consistent with that of <code>decltype_</code>. In particular, see <code>decltype_</code>'s documentation to understand why references are always stripped by <code>sizeof_</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="equal_8hpp.html">boost/hana/equal.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"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>X { };</div><div class="line">static_assert(hana::sizeof_(hana::type_c<X>) == <span class="keyword">sizeof</span>(X), <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line">static_assert(hana::sizeof_(1) == <span class="keyword">sizeof</span>(1), <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::sizeof_(hana::type_c<int>) == <span class="keyword">sizeof</span>(<span class="keywordtype">int</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="a6fd9ac456f4b5574dcb16384dbb85736"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a6fd9ac456f4b5574dcb16384dbb85736">◆ </a></span>alignof_</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 alignof_</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="keyword">using</span> T = <span class="keyword">typename</span> decltype(hana::decltype_(x))::type;</div><div class="line"> <span class="keywordflow">return</span> hana::size_c<<span class="keyword">alignof</span>(T)>;</div><div class="line"> }</div></div><!-- fragment -->
- <p><code>alignof</code> keyword, lifted to Hana. </p>
- <p><code>alignof_</code> is somewhat equivalent to <code>alignof</code> in that it returns the alignment required by any instance of a type, but it takes a <code>type</code> and returns its alignment as an <code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">integral_constant</a></code>. Like <code>sizeof</code> which works for expressions and type-ids, <code>alignof_</code> can also be called on an arbitrary expression. Specifically, given an expression <code>expr</code> and a C++ type <code>T</code>, <code>alignof_</code> satisfies </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a6fd9ac456f4b5574dcb16384dbb85736">alignof_</a>(expr) == <span class="keywordtype">size_t</span><<span class="keyword">alignof</span>(decltype(expr) with references stripped)></div><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a6fd9ac456f4b5574dcb16384dbb85736">alignof_</a>(type_c<T>) == <span class="keywordtype">size_t</span><<span class="keyword">alignof</span>(T)></div></div><!-- fragment --><p>The behavior of <code>alignof_</code> is consistent with that of <code>decltype_</code>. In particular, see <code>decltype_</code>'s documentation to understand why references are always stripped by <code>alignof_</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="equal_8hpp.html">boost/hana/equal.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"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">struct </span>X { };</div><div class="line">static_assert(hana::alignof_(hana::type_c<X>) == <span class="keyword">alignof</span>(X), <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line">static_assert(hana::alignof_(1) == <span class="keyword">alignof</span>(decltype(1)), <span class="stringliteral">""</span>);</div><div class="line">static_assert(hana::alignof_(hana::type_c<int>) == <span class="keyword">alignof</span>(<span class="keywordtype">int</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="a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b"></a>
- <h2 class="memtitle"><span class="permalink"><a href="#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b">◆ </a></span>is_valid</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_valid</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> [](<span class="keyword">auto</span>&& ...args) {</div><div class="line"> <span class="keywordflow">return</span> whether f(args...) is a valid expression;</div><div class="line"> };</div><div class="line"> }</div></div><!-- fragment -->
- <p>Checks whether a SFINAE-friendly expression is valid. </p>
- <p>Given a SFINAE-friendly function, <code>is_valid</code> returns whether the function call is valid with the given arguments. Specifically, given a function <code>f</code> and arguments <code>args...</code>, </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b">is_valid</a>(f, args...) == whether f(args...) is valid</div></div><!-- fragment --><p>The result is returned as a compile-time <code>Logical</code>. Furthermore, <code>is_valid</code> can be used in curried form as follows: </p><div class="fragment"><div class="line"><a class="code" href="structboost_1_1hana_1_1type.html#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b">is_valid</a>(f)(args...)</div></div><!-- fragment --><p>This syntax makes it easy to create functions that check the validity of a generic expression on any given argument(s).</p>
- <dl class="section warning"><dt>Warning</dt><dd>To check whether calling a nullary function <code>f</code> is valid, one should use the <code>is_valid(f)()</code> syntax. Indeed, <code>is_valid(f /* no args */)</code> will be interpreted as the currying of <code>is_valid</code> to <code>f</code> rather than the application of <code>is_valid</code> to <code>f</code> and no arguments.</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="not_8hpp.html">boost/hana/not.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="preprocessor">#include <vector></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"> <span class="comment">// Checking for a member</span></div><div class="line"> <span class="keyword">struct </span>Person { std::string name; };</div><div class="line"> <span class="keyword">auto</span> has_name = hana::is_valid([](<span class="keyword">auto</span>&& p) -> decltype((<span class="keywordtype">void</span>)p.name) { });</div><div class="line"></div><div class="line"> Person joe{<span class="stringliteral">"Joe"</span>};</div><div class="line"> static_assert(has_name(joe), <span class="stringliteral">""</span>);</div><div class="line"> static_assert(!has_name(1), <span class="stringliteral">""</span>);</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// Checking for a nested type</span></div><div class="line"> <span class="keyword">auto</span> has_value_type = hana::is_valid([](<span class="keyword">auto</span> t) -> hana::type<</div><div class="line"> <span class="keyword">typename</span> decltype(t)::type::value_type</div><div class="line"> > { });</div><div class="line"></div><div class="line"> static_assert(has_value_type(hana::type_c<std::vector<int>>), <span class="stringliteral">""</span>);</div><div class="line"> static_assert(!has_value_type(hana::type_c<Person>), <span class="stringliteral">""</span>);</div><div class="line">}</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_1type.html">type</a></li>
- </ul>
- </div>
- </body>
- </html>
|