Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / doc / html / structboost_1_1hana_1_1common.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::common&lt; T, U, 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_1common.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::common&lt; T, U, 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, typename U, optional when-based enabler&gt;<br />
130 struct boost::hana::common&lt; T, U, enabler &gt;</h3>
131
132 <p>Metafunction returning the common data type between two data types. </p>
133 <p><code>common</code> is a natural extension of the <code>std::common_type</code> metafunction to data types. Given two data types <code>T</code> and <code>U</code>, we say that they share a common type <code>C</code> if both objects of data type <code>T</code> and objects of data type <code>U</code> may be converted (using <code>to</code>) to an object of data type <code>C</code>, and if that conversion is equality preserving. In other words, this means that for any objects <code>t1, t2</code> of data type <code>T</code> and <code>u1, u2</code> of data type <code>U</code>, the following law is satisfied: </p><div class="fragment"><div class="line">to&lt;C&gt;(t1) == to&lt;C&gt;(t2)  if and only if  t1 == t2</div><div class="line"><a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>&lt;C&gt;(u1) == <a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>&lt;C&gt;(u2)  if and only if  u1 == u2</div></div><!-- fragment --><p>The role of <code>common</code> is to provide an alias to such a <code>C</code> if it exists. In other words, if <code>T</code> and <code>U</code> have a common data type <code>C</code>, <code>common&lt;T, U&gt;::type</code> is an alias to <code>C</code>. Otherwise, <code>common&lt;T, U&gt;</code> has no nested <code>type</code> and can be used in dependent contexts to exploit SFINAE. By default, the exact steps followed by <code>common</code> to determine the common type <code>C</code> of <code>T</code> and <code>U</code> are</p><ol type="1">
134 <li>If <code>T</code> and <code>U</code> are the same, then <code>C</code> is <code>T</code>.</li>
135 <li>Otherwise, if <code>true ? std::declval&lt;T&gt;() : std::declval&lt;U&gt;()</code> is well-formed, then <code>C</code> is the type of this expression after using <code>std::decay</code> on it. This is exactly the type that would have been returned by <code>std::common_type</code>, except that custom specializations of <code>std::common_type</code> are not taken into account.</li>
136 <li>Otherwise, no common data type is detected and <code>common&lt;T, U&gt;</code> does not have a nested <code>type</code> alias, unless it is specialized explicitly.</li>
137 </ol>
138 <p>As point 3 suggests, it is also possible (and sometimes necessary) to specialize <code>common</code> in the <code><a class="el" href="namespaceboost_1_1hana.html" title="Namespace containing everything in the library. ">boost::hana</a></code> namespace for pairs of custom data types when the default behavior of <code>common</code> is not sufficient. Note that <code>when</code>-based specialization is supported when specializing <code>common</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>
139 <blockquote class="doxtable">
140 <h4>Rationale for requiring the conversion to be equality-preserving</h4>
141 <p>This decision is aligned with a proposed concept design for the standard library (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf">N3351</a>). Also, if we did not require this, then all data types would trivially share the common data type <code>void</code>, since all objects can be converted to it. </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_2common_8hpp.html">boost/hana/core/common.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"><span class="keyword">struct </span>Person { };</div><div class="line"><span class="keyword">struct </span>Employee : Person { };</div><div class="line"></div><div class="line">static_assert(std::is_same&lt;hana::common&lt;int, float&gt;::type, <span class="keywordtype">float</span>&gt;{}, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">static_assert(std::is_same&lt;hana::common&lt;Person, Employee&gt;::type, Person&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_1common.html">common</a></li>
157   </ul>
158 </div>
159 </body>
160 </html>