Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / doc / html / structboost_1_1hana_1_1tag__of.html
1 <!--
2 Copyright Louis Dionne 2013-2017
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 -->
6 <!-- boost-no-inspect -->
7 <!-- HTML header for doxygen 1.8.9.1-->
8 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9 <html xmlns="http://www.w3.org/1999/xhtml">
10 <head>
11 <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
12 <meta http-equiv="X-UA-Compatible" content="IE=9"/>
13 <meta name="generator" content="Doxygen 1.8.11"/>
14 <title>Boost.Hana: boost::hana::tag_of&lt; T, enabler &gt; Struct Template Reference</title>
15 <link href="tabs.css" rel="stylesheet" type="text/css"/>
16 <script type="text/javascript" src="jquery.js"></script>
17 <script type="text/javascript" src="dynsections.js"></script>
18 <link href="navtree.css" rel="stylesheet" type="text/css"/>
19 <script type="text/javascript" src="resize.js"></script>
20 <script type="text/javascript" src="navtreedata.js"></script>
21 <script type="text/javascript" src="navtree.js"></script>
22 <script type="text/javascript">
23   $(document).ready(initResizable);
24   $(window).load(resizeHeight);
25 </script>
26 <link href="search/search.css" rel="stylesheet" type="text/css"/>
27 <script type="text/javascript" src="search/searchdata.js"></script>
28 <script type="text/javascript" src="search/search.js"></script>
29 <script type="text/javascript">
30   $(document).ready(function() { init_search(); });
31 </script>
32 <script type="text/x-mathjax-config">
33   MathJax.Hub.Config({
34     extensions: ["tex2jax.js"],
35     jax: ["input/TeX","output/HTML-CSS"],
36 });
37 // Copyright Louis Dionne 2013-2017
38 // Distributed under the Boost Software License, Version 1.0.
39 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
40 MathJax.Hub.Config({
41     "HTML-CSS": {
42         linebreaks: {
43             automatic: true,
44             width: "75% container"
45         }
46     }
47 });
48 </script><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
49 <link href="doxygen.css" rel="stylesheet" type="text/css" />
50 <!-- Additional javascript for drawing charts. -->
51 <script type="text/javascript" src="highcharts.js"></script>
52 <script type="text/javascript" src="highcharts-data.js"></script>
53 <script type="text/javascript" src="highcharts-exporting.js"></script>
54 <script type="text/javascript" src="chart.js"></script>
55 <script type="text/javascript" src="hana.js"></script>
56 </head>
57 <body>
58 <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
59 <div id="titlearea">
60 <table cellspacing="0" cellpadding="0">
61  <tbody>
62  <tr style="height: 56px;">
63   <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
64   <td style="padding-left: 0.5em;">
65    <div id="projectname">Boost.Hana
66    &#160;<span id="projectnumber">1.1.0</span>
67    </div>
68    <div id="projectbrief">Your standard library for metaprogramming</div>
69   </td>
70    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
71         <span class="left">
72           <img id="MSearchSelect" src="search/mag_sel.png"
73                onmouseover="return searchBox.OnSearchSelectShow()"
74                onmouseout="return searchBox.OnSearchSelectHide()"
75                alt=""/>
76           <input type="text" id="MSearchField" value="Search" accesskey="S"
77                onfocus="searchBox.OnSearchFieldFocus(true)" 
78                onblur="searchBox.OnSearchFieldFocus(false)" 
79                onkeyup="searchBox.OnSearchFieldChange(event)"/>
80           </span><span class="right">
81             <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
82           </span>
83         </div>
84 </td>
85  </tr>
86  </tbody>
87 </table>
88 </div>
89 <!-- end header part -->
90 <!-- Generated by Doxygen 1.8.11 -->
91 <script type="text/javascript">
92 var searchBox = new SearchBox("searchBox", "search",false,'Search');
93 </script>
94 </div><!-- top -->
95 <div id="side-nav" class="ui-resizable side-nav-resizable">
96   <div id="nav-tree">
97     <div id="nav-tree-contents">
98       <div id="nav-sync" class="sync"></div>
99     </div>
100   </div>
101   <div id="splitbar" style="-moz-user-select:none;" 
102        class="ui-resizable-handle">
103   </div>
104 </div>
105 <script type="text/javascript">
106 $(document).ready(function(){initNavTree('structboost_1_1hana_1_1tag__of.html','');});
107 </script>
108 <div id="doc-content">
109 <!-- window showing the filter options -->
110 <div id="MSearchSelectWindow"
111      onmouseover="return searchBox.OnSearchSelectShow()"
112      onmouseout="return searchBox.OnSearchSelectHide()"
113      onkeydown="return searchBox.OnSearchSelectKey(event)">
114 </div>
115
116 <!-- iframe showing the search results (closed by default) -->
117 <div id="MSearchResultsWindow">
118 <iframe src="javascript:void(0)" frameborder="0" 
119         name="MSearchResults" id="MSearchResults">
120 </iframe>
121 </div>
122
123 <div class="header">
124   <div class="headertitle">
125 <div class="title">boost::hana::tag_of&lt; T, enabler &gt; Struct Template Reference<div class="ingroups"><a class="el" href="group__group-core.html">Core</a></div></div>  </div>
126 </div><!--header-->
127 <div class="contents">
128 <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
129 <div class="textblock"><h3>template&lt;typename T, optional when-based enabler&gt;<br />
130 struct boost::hana::tag_of&lt; T, enabler &gt;</h3>
131
132 <p>Metafunction returning the tag associated to <code>T</code>. </p>
133 <p>There are several ways to specify the tag of a C++ type. If it's a user-defined type, one can define a nested <code>hana_tag</code> alias: </p><div class="fragment"><div class="line"><span class="keyword">struct </span>MyUserDefinedType {</div><div class="line">    <span class="keyword">using</span> hana_tag = MyTag;</div><div class="line">};</div></div><!-- fragment --><p>Sometimes, however, the C++ type can't be modified (if it's in a foreign library) or simply can't have nested types (if it's not a struct or class). In those cases, using a nested alias is impossible and so ad-hoc customization is also supported by specializing <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> in the <code><a class="el" href="namespaceboost_1_1hana.html" title="Namespace containing everything in the library. ">boost::hana</a></code> namespace: </p><div class="fragment"><div class="line"><span class="keyword">struct </span>i_cant_modify_this;</div><div class="line"></div><div class="line"><span class="keyword">namespace </span><a class="code" href="namespaceboost.html">boost</a> { <span class="keyword">namespace </span>hana {</div><div class="line">    <span class="keyword">template</span> &lt;&gt;</div><div class="line">    <span class="keyword">struct </span>tag_of&lt;i_cant_modify_this&gt; {</div><div class="line">        <span class="keyword">using</span> type = MyTag;</div><div class="line">    };</div><div class="line">}}</div></div><!-- fragment --><p><code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> can also be specialized for all C++ types satisfying some boolean condition using <code>when</code>. <code>when</code> accepts a single compile-time boolean and enables the specialization of <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> if and only if that boolean is <code>true</code>. This is similar to the well known C++ idiom of using a dummy template parameter with <code>std::enable_if</code> and relying on SFINAE. For example, we could specify the tag of all <code><a class="el" href="structboost_1_1fusion_1_1vector.html" title="Adapter for Boost.Fusion vectors. ">fusion::vector</a></code>s by doing: </p><div class="fragment"><div class="line"><span class="keyword">struct </span>BoostFusionVector;</div><div class="line"></div><div class="line"><span class="keyword">namespace </span><a class="code" href="namespaceboost.html">boost</a> { <span class="keyword">namespace </span>hana {</div><div class="line">    <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line">    <span class="keyword">struct </span>tag_of&lt;T, when&lt;</div><div class="line">        <a class="code" href="namespacestd.html">std</a>::is_same&lt;</div><div class="line">            typename fusion::traits::tag_of&lt;T&gt;::type,</div><div class="line">            fusion::traits::tag_of&lt;fusion::vector&lt;&gt;&gt;::type</div><div class="line">        &gt;{}</div><div class="line">    &gt;&gt; {</div><div class="line">        <span class="keyword">using</span> type = BoostFusionVector;</div><div class="line">    };</div><div class="line">}}</div></div><!-- fragment --><p>Also, when it is not specialized and when the given C++ type does not have a nested <code>hana_tag</code> alias, <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;T&gt;</code> returns <code>T</code> itself. This makes tags a simple extension of normal C++ types. This is <em>super</em> useful, mainly for two reasons. First, this allows Hana to adopt a reasonable default behavior for some operations involving types that have no notion of tags. For example, Hana allows comparing with <code>equal</code> any two objects for which a valid <code>operator==</code> is defined, and that without any work on the user side. Second, it also means that you can ignore tags completely if you don't need their functionality; just use the normal C++ type of your objects and everything will "just work".</p>
134 <p>Finally, also note that <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;T&gt;</code> is always equivalent to <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;U&gt;</code>, where <code>U</code> is the type <code>T</code> after being stripped of all references and cv-qualifiers. This makes it unnecessary to specialize <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> for all reference and cv combinations, which would be a real pain. Also, <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> is required to be idempotent. In other words, it must always be the case that <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;<a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;T&gt;::type&gt;::type</code> is equivalent to <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a>&lt;T&gt;::type</code>.</p>
135 <blockquote class="doxtable">
136 <p><b>Tip 1</b><br />
137 If compile-time performance is a serious concern, consider specializing the <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code> metafunction in Hana's namespace. When unspecialized, the metafunction has to use SFINAE, which tends to incur a larger compile-time overhead. For heavily used templated types, this can potentially make a difference. </p>
138 </blockquote>
139 <blockquote class="doxtable">
140 <p><b>Tip 2</b><br />
141 Consider using <code>tag_of_t</code> alias instead of <code><a class="el" href="structboost_1_1hana_1_1tag__of.html" title="Metafunction returning the tag associated to T. ">tag_of</a></code>, which reduces the amount of typing in dependent contexts. </p>
142 </blockquote>
143 <h2>Example </h2>
144 <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="core_2tag__of_8hpp.html">boost/hana/core/tag_of.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;type_traits&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line">static_assert(std::is_same&lt;hana::tag_of&lt;int&gt;::type, <span class="keywordtype">int</span>&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(std::is_same&lt;hana::tag_of&lt;int&amp;&gt;::type, <span class="keywordtype">int</span>&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(std::is_same&lt;hana::tag_of&lt;int const&amp;&gt;::type, <span class="keywordtype">int</span>&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keyword">struct </span>PersonTag;</div><div class="line"><span class="keyword">struct </span>Person { <span class="keyword">using</span> hana_tag = PersonTag; };</div><div class="line">static_assert(std::is_same&lt;hana::tag_of&lt;Person&gt;::type, PersonTag&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(std::is_same&lt;hana::tag_of&lt;Person volatile&amp;&amp;&gt;::type, PersonTag&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() { }</div></div><!-- fragment --> </div></div><!-- contents -->
145 </div><!-- doc-content -->
146 <!--
147 Copyright Louis Dionne 2013-2017
148 Distributed under the Boost Software License, Version 1.0.
149 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
150 -->
151 <!-- boost-no-inspect -->
152 <!-- HTML footer for doxygen 1.8.9.1-->
153 <!-- start footer part -->
154 <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
155   <ul>
156     <li class="navelem"><a class="el" href="namespaceboost.html">boost</a></li><li class="navelem"><a class="el" href="namespaceboost_1_1hana.html">hana</a></li><li class="navelem"><a class="el" href="structboost_1_1hana_1_1tag__of.html">tag_of</a></li>
157   </ul>
158 </div>
159 </body>
160 </html>