188 lines
12 KiB
HTML
188 lines
12 KiB
HTML
<!--
|
|
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.20"/>
|
|
<title>Boost.Hana: boost::hana::common< T, U, enabler > 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>
|
|
<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.7.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.svg"
|
|
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.svg" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.20 -->
|
|
<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_1common.html',''); initResizable(); });
|
|
/* @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="headertitle">
|
|
<div class="title">boost::hana::common< T, U, enabler > Struct Template Reference<div class="ingroups"><a class="el" href="group__group-core.html">Core</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, typename U, optional when-based enabler><br />
|
|
struct boost::hana::common< T, U, enabler ></h3>
|
|
|
|
<p>Metafunction returning the common data type between two data types. </p>
|
|
<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<C>(t1) == to<C>(t2) <span class="keywordflow">if</span> and only <span class="keywordflow">if</span> t1 == t2</div>
|
|
<div class="line">to<C>(u1) == to<C>(u2) <span class="keywordflow">if</span> and only <span class="keywordflow">if</span> 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<T, U>::type</code> is an alias to <code>C</code>. Otherwise, <code>common<T, U></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">
|
|
<li>If <code>T</code> and <code>U</code> are the same, then <code>C</code> is <code>T</code>.</li>
|
|
<li>Otherwise, if <code>true ? std::declval<T>() : std::declval<U>()</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>
|
|
<li>Otherwise, no common data type is detected and <code>common<T, U></code> does not have a nested <code>type</code> alias, unless it is specialized explicitly.</li>
|
|
</ol>
|
|
<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>
|
|
<blockquote class="doxtable">
|
|
<p></p>
|
|
</blockquote>
|
|
<h4><a class="anchor" id="autotoc_md185"></a>
|
|
Rationale for requiring the conversion to be equality-preserving</h4>
|
|
<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>
|
|
<h2><a class="anchor" id="autotoc_md186"></a>
|
|
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="core_2common_8hpp.html">boost/hana/core/common.hpp</a>></span></div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="preprocessor">#include <type_traits></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<hana::common<int, float>::type, <span class="keywordtype">float</span>>{}, <span class="stringliteral">""</span>);</div>
|
|
<div class="line">static_assert(std::is_same<hana::common<Person, Employee>::type, Person>{}, <span class="stringliteral">""</span>);</div>
|
|
<div class="line"> </div>
|
|
<div class="line"><span class="keywordtype">int</span> main() { }</div>
|
|
</div><!-- fragment --> </div></div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<div class="ttc" id="acore_2common_8hpp_html"><div class="ttname"><a href="core_2common_8hpp.html">common.hpp</a></div><div class="ttdoc">Defines boost::hana::common and boost::hana::common_t.</div></div>
|
|
<div class="ttc" id="anamespaceboost_1_1hana_html"><div class="ttname"><a href="namespaceboost_1_1hana.html">boost::hana</a></div><div class="ttdoc">Namespace containing everything in the library.</div><div class="ttdef"><b>Definition:</b> accessors.hpp:20</div></div>
|
|
<!--
|
|
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_1common.html">common</a></li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|