group__group-Comparable.html 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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.15"/>
  14. <title>Boost.Hana: Comparable</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. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  24. $(document).ready(initResizable);
  25. /* @license-end */</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. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  31. $(document).ready(function() { init_search(); });
  32. /* @license-end */
  33. </script>
  34. <script type="text/x-mathjax-config">
  35. MathJax.Hub.Config({
  36. extensions: ["tex2jax.js"],
  37. jax: ["input/TeX","output/HTML-CSS"],
  38. });
  39. // Copyright Louis Dionne 2013-2017
  40. // Distributed under the Boost Software License, Version 1.0.
  41. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  42. MathJax.Hub.Config({
  43. "HTML-CSS": {
  44. linebreaks: {
  45. automatic: true,
  46. width: "75% container"
  47. }
  48. }
  49. });
  50. </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
  51. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  52. <!-- Additional javascript for drawing charts. -->
  53. <script type="text/javascript" src="highcharts.js"></script>
  54. <script type="text/javascript" src="highcharts-data.js"></script>
  55. <script type="text/javascript" src="highcharts-exporting.js"></script>
  56. <script type="text/javascript" src="chart.js"></script>
  57. <script type="text/javascript" src="hana.js"></script>
  58. </head>
  59. <body>
  60. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  61. <div id="titlearea">
  62. <table cellspacing="0" cellpadding="0">
  63. <tbody>
  64. <tr style="height: 56px;">
  65. <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  66. <td style="padding-left: 0.5em;">
  67. <div id="projectname">Boost.Hana
  68. &#160;<span id="projectnumber">1.6.0</span>
  69. </div>
  70. <div id="projectbrief">Your standard library for metaprogramming</div>
  71. </td>
  72. <td> <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <!-- end header part -->
  92. <!-- Generated by Doxygen 1.8.15 -->
  93. <script type="text/javascript">
  94. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  95. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  96. /* @license-end */
  97. </script>
  98. </div><!-- top -->
  99. <div id="side-nav" class="ui-resizable side-nav-resizable">
  100. <div id="nav-tree">
  101. <div id="nav-tree-contents">
  102. <div id="nav-sync" class="sync"></div>
  103. </div>
  104. </div>
  105. <div id="splitbar" style="-moz-user-select:none;"
  106. class="ui-resizable-handle">
  107. </div>
  108. </div>
  109. <script type="text/javascript">
  110. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  111. $(document).ready(function(){initNavTree('group__group-Comparable.html','');});
  112. /* @license-end */
  113. </script>
  114. <div id="doc-content">
  115. <!-- window showing the filter options -->
  116. <div id="MSearchSelectWindow"
  117. onmouseover="return searchBox.OnSearchSelectShow()"
  118. onmouseout="return searchBox.OnSearchSelectHide()"
  119. onkeydown="return searchBox.OnSearchSelectKey(event)">
  120. </div>
  121. <!-- iframe showing the search results (closed by default) -->
  122. <div id="MSearchResultsWindow">
  123. <iframe src="javascript:void(0)" frameborder="0"
  124. name="MSearchResults" id="MSearchResults">
  125. </iframe>
  126. </div>
  127. <div class="header">
  128. <div class="summary">
  129. <a href="#var-members">Variables</a> </div>
  130. <div class="headertitle">
  131. <div class="title">Comparable<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>The <code>Comparable</code> concept defines equality and inequality. </p>
  136. <p>Intuitively, <code>Comparable</code> objects must define a binary predicate named <code>equal</code> that returns whether both objects represent the same abstract value. In other words, <code>equal</code> must check for deep equality. Since "representing the same abstract value" is difficult to express formally, the exact meaning of equality is partially left to interpretation by the programmer with the following guidelines:<br />
  137. </p><ol type="1">
  138. <li>Equality should be compatible with copy construction; copy constructing a value yields an <code>equal</code> value.</li>
  139. <li>Equality should be independent of representation; an object representing a fraction as <code>4/8</code> should be <code>equal</code> to an object representing a fraction as <code>2/4</code>, because they both represent the mathematical object <code>1/2</code>.</li>
  140. </ol>
  141. <p>Moreover, <code>equal</code> must exhibit properties that make it intuitive to use for determining the equivalence of objects, which is formalized by the laws for <code>Comparable</code>.</p>
  142. <h2>Minimal complete definition </h2>
  143. <ol type="1">
  144. <li><code>equal</code><br />
  145. When <code>equal</code> is defined, <code>not_equal</code> is implemented by default as its complement. For all objects <code>x</code>, <code>y</code> of a <code>Comparable</code> tag, <div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y) == <a class="code" href="group__group-Logical.html#ga4a7c9d7037601d5e553fd20777958980">not_</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y))</div></div><!-- fragment --></li>
  146. </ol>
  147. <h2>Laws </h2>
  148. <p><code>equal</code> must define an <a href="http://en.wikipedia.org/wiki/Equivalence_relation#Definition">equivalence relation</a>, and <code>not_equal</code> must be its complement. In other words, for all objects <code>a</code>, <code>b</code>, <code>c</code> with a <code>Comparable</code> tag, the following must hold: </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, a) <span class="comment">// Reflexivity</span></div><div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b) <a class="code" href="group__group-Monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(b, a) <span class="comment">// Symmetry</span></div><div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b) &amp;&amp; <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(b, c) <a class="code" href="group__group-Monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, c) <span class="comment">// Transitivity</span></div><div class="line"><a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(a, b) is equivalent <a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a> <a class="code" href="group__group-Logical.html#ga4a7c9d7037601d5e553fd20777958980">not_</a>(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(a, b))</div></div><!-- fragment --><h2>Concrete models </h2>
  149. <p><code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">hana::integral_constant</a></code>, <code><a class="el" href="structboost_1_1hana_1_1map.html" title="Basic associative container requiring unique, Comparable and Hashable keys.">hana::map</a></code>, <code><a class="el" href="structboost_1_1hana_1_1optional.html" title="Optional value whose optional-ness is known at compile-time.">hana::optional</a></code>, <code><a class="el" href="structboost_1_1hana_1_1pair.html" title="Generic container for two elements.">hana::pair</a></code>, <code><a class="el" href="structboost_1_1hana_1_1range.html" title="Compile-time half-open interval of hana::integral_constants.">hana::range</a></code>, <code><a class="el" href="structboost_1_1hana_1_1set.html" title="Basic unordered container requiring unique, Comparable and Hashable keys.">hana::set</a></code>, <code><a class="el" href="structboost_1_1hana_1_1string.html" title="Compile-time string.">hana::string</a></code>, <code><a class="el" href="structboost_1_1hana_1_1tuple.html" title="General purpose index-based heterogeneous sequence with a fixed length.">hana::tuple</a></code>, <code><a class="el" href="structboost_1_1hana_1_1type.html" title="C++ type in value-level representation.">hana::type</a></code></p>
  150. <h2>Free model for <code>EqualityComparable</code> data types </h2>
  151. <p>Two data types <code>T</code> and <code>U</code> that model the cross-type EqualityComparable concept presented in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf">N3351</a> automatically model the <code>Comparable</code> concept by setting </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y) = (x == y)</div></div><!-- fragment --><p> Note that this also makes EqualityComparable types in the <a href="http://en.cppreference.com/w/cpp/named_req/EqualityComparable">usual sense</a> models of <code>Comparable</code> in the same way.</p>
  152. <h2>Equality-preserving functions </h2>
  153. <p>Let <code>A</code> and <code>B</code> be two <code>Comparable</code> tags. A function \(f : A \to B\) is said to be equality-preserving if it preserves the structure of the <code>Comparable</code> concept, which can be rigorously stated as follows. For all objects <code>x</code>, <code>y</code> of tag <code>A</code>, </p><div class="fragment"><div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y) <a class="code" href="group__group-Monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y))</div></div><!-- fragment --><p> Equivalently, we simply require that <code>f</code> is a function in the usual mathematical sense. Another property is <a href="http://en.wikipedia.org/wiki/Injective_function">injectivity</a>, which can be viewed as being a "lossless" mapping. This property can be stated as </p><div class="fragment"><div class="line"><span class="keywordflow">if</span> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y)) <a class="code" href="group__group-Monad.html#gaaddd3789de43cf989babb10cdc0b447a">then</a> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div></div><!-- fragment --><p> This is equivalent to saying that <code>f</code> maps distinct elements to distinct elements, hence the "lossless" analogy. In other words, <code>f</code> will not collapse distinct elements from its domain into a single element in its image, thus losing information.</p>
  154. <p>These functions are very important, especially equality-preserving ones, because they allow us to reason simply about programs. Also note that the property of being equality-preserving is taken for granted in mathematics because it is part of the definition of a function. We feel it is important to make the distinction here because programming has evolved differently and as a result programmers are used to work with functions that do not preserve equality.</p>
  155. <h2>Cross-type version of the methods </h2>
  156. <p>The <code>equal</code> and <code>not_equal</code> methods are "overloaded" to handle distinct tags with certain properties. Specifically, they are defined for <em>distinct</em> tags <code>A</code> and <code>B</code> such that</p><ol type="1">
  157. <li><code>A</code> and <code>B</code> share a common tag <code>C</code>, as determined by the <code>common</code> metafunction</li>
  158. <li><code>A</code>, <code>B</code> and <code>C</code> are all <code>Comparable</code> when taken individually</li>
  159. <li>\( \mathtt{to&lt;C&gt;} : A \to C \) and \(\mathtt{to&lt;C&gt;} : B \to C\) are both equality-preserving and injective (i.e. they are embeddings), as determined by the <code>is_embedding</code> metafunction.</li>
  160. </ol>
  161. <p>The method definitions for tags satisfying the above properties are </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y) = <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(to&lt;C&gt;(x), to&lt;C&gt;(y))</div><div class="line"><a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y) = <a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(to&lt;C&gt;(x), to&lt;C&gt;(y))</div></div><!-- fragment --><h2>Important note: special behavior of <code>equal</code> </h2>
  162. <p>In the context of programming with heterogeneous values, it is useful to have unrelated objects compare <code>false</code> instead of triggering an error. For this reason, <code>equal</code> adopts a special behavior for unrelated objects of tags <code>T</code> and <code>U</code> that do not satisfy the above requirements for the cross-type overloads. Specifically, when <code>T</code> and <code>U</code> are unrelated (i.e. <code>T</code> can't be converted to <code>U</code> and vice-versa), comparing objects with those tags yields a compile-time false value. This has the effect that unrelated objects like <code>float</code> and <code>std::string</code> will compare false, while comparing related objects that can not be safely embedded into the same super structure (like <code>long long</code> and <code>float</code> because of the precision loss) will trigger a compile-time assertion. Also note that for any tag <code>T</code> for which the minimal complete definition of <code>Comparable</code> is not provided, a compile-time assertion will also be triggered because <code>T</code> and <code>T</code> trivially share the common tag <code>T</code>, which is the expected behavior. This design choice aims to provide more flexibility for comparing objects, while still rejecting usage patterns that are most likely programming errors. </p>
  163. <table class="memberdecls">
  164. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  165. Variables</h2></td></tr>
  166. <tr class="memitem:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">boost::hana::comparing</a></td></tr>
  167. <tr class="memdesc:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a function performing <code>equal</code> after applying a transformation to both arguments.<code>comparing</code> creates an equivalence relation based on the result of applying a function to some objects, which is especially useful in conjunction with algorithms that accept a custom predicate that must represent an equivalence relation. <a href="group__group-Comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">More...</a><br /></td></tr>
  168. <tr class="separator:ga9c2ffe2e51780e57a38d9e7e31b87cdc"><td class="memSeparator" colspan="2">&#160;</td></tr>
  169. <tr class="memitem:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">boost::hana::equal</a></td></tr>
  170. <tr class="memdesc:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Logical</code> representing whether <code>x</code> is equal to <code>y</code>.The <code>equal</code> function can be called in two different ways. First, it can be called like a normal function: <a href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">More...</a><br /></td></tr>
  171. <tr class="separator:gacaf1ebea6b3ab96ac9dcb82f0e64e547"><td class="memSeparator" colspan="2">&#160;</td></tr>
  172. <tr class="memitem:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">boost::hana::not_equal</a></td></tr>
  173. <tr class="memdesc:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a <code>Logical</code> representing whether <code>x</code> is not equal to <code>y</code>.The <code>not_equal</code> function can be called in two different ways. First, it can be called like a normal function: <a href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">More...</a><br /></td></tr>
  174. <tr class="separator:gae33be2e0d5e04f19082f4b7740dfc9cd"><td class="memSeparator" colspan="2">&#160;</td></tr>
  175. </table>
  176. <h2 class="groupheader">Variable Documentation</h2>
  177. <a id="ga9c2ffe2e51780e57a38d9e7e31b87cdc"></a>
  178. <h2 class="memtitle"><span class="permalink"><a href="#ga9c2ffe2e51780e57a38d9e7e31b87cdc">&#9670;&nbsp;</a></span>comparing</h2>
  179. <div class="memitem">
  180. <div class="memproto">
  181. <table class="memname">
  182. <tr>
  183. <td class="memname">constexpr auto boost::hana::comparing</td>
  184. </tr>
  185. </table>
  186. </div><div class="memdoc">
  187. <p><code>#include &lt;<a class="el" href="fwd_2comparing_8hpp.html">boost/hana/fwd/comparing.hpp</a>&gt;</code></p>
  188. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; f) {</div><div class="line"> <span class="keywordflow">return</span> [perfect-<a class="code" href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">capture</a>](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div><div class="line"> <span class="keywordflow">return</span> <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(forwarded(x)), f(forwarded(y)));</div><div class="line"> };</div><div class="line"> }</div><div class="ttc" id="group__group-functional_html_ga41ada6b336e9d5bcb101ff0c737acbd0"><div class="ttname"><a href="group__group-functional.html#ga41ada6b336e9d5bcb101ff0c737acbd0">boost::hana::capture</a></div><div class="ttdeci">constexpr auto capture</div><div class="ttdoc">Create a function capturing the given variables.</div><div class="ttdef"><b>Definition:</b> capture.hpp:45</div></div>
  189. <div class="ttc" id="group__group-Comparable_html_gacaf1ebea6b3ab96ac9dcb82f0e64e547"><div class="ttname"><a href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">boost::hana::equal</a></div><div class="ttdeci">constexpr auto equal</div><div class="ttdoc">Returns a Logical representing whether x is equal to y.The equal function can be called in two differ...</div><div class="ttdef"><b>Definition:</b> equal.hpp:64</div></div>
  190. </div><!-- fragment -->
  191. <p>Returns a function performing <code>equal</code> after applying a transformation to both arguments.<code>comparing</code> creates an equivalence relation based on the result of applying a function to some objects, which is especially useful in conjunction with algorithms that accept a custom predicate that must represent an equivalence relation. </p>
  192. <p>Specifically, <code>comparing</code> is such that </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">comparing</a>(f) == <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a> ^<a class="code" href="group__group-functional.html#ga35c4fc3c5677b9f558150b90e74d3ab1">on</a>^ f</div></div><!-- fragment --><p> or, equivalently, </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">comparing</a>(f)(x, y) == <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(f(x), f(y))</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>This is not a tag-dispatched method (hence it can't be customized), but just a convenience function provided with the <code>Comparable</code> concept.</dd></dl>
  193. <h2>Signature </h2>
  194. <p>Given a Logical <code>Bool</code> and a Comparable <code>B</code>, the signature is \( \mathtt{comparing} : (A \to B) \to (A \times A \to Bool) \).</p>
  195. <h2>Example </h2>
  196. <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="comparing_8hpp.html">boost/hana/comparing.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="group_8hpp.html">boost/hana/group.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="length_8hpp.html">boost/hana/length.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="range_8hpp.html">boost/hana/range.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&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="keywordtype">int</span> main() {</div><div class="line"> constexpr <span class="keyword">auto</span> sequences = hana::make_tuple(</div><div class="line"> hana::make_tuple(1, 2, 3),</div><div class="line"> hana::make_tuple(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>, <span class="charliteral">&#39;z&#39;</span>),</div><div class="line"> hana::range_c&lt;long, 0, 1&gt;,</div><div class="line"> hana::tuple_t&lt;char, int&gt;,</div><div class="line"> hana::range_c&lt;int, 0, 2&gt;,</div><div class="line"> hana::make_tuple(123.4, <span class="keyword">nullptr</span>)</div><div class="line"> );</div><div class="line"></div><div class="line"> constexpr <span class="keyword">auto</span> grouped = <a class="code" href="group__group-Sequence.html#gacefca884b3580664b63238cf8ba33fd3">hana::group</a>.by(<a class="code" href="group__group-Comparable.html#ga9c2ffe2e51780e57a38d9e7e31b87cdc">hana::comparing</a>(<a class="code" href="group__group-Foldable.html#gaf0f8f717245620dc28cd7d7fa44d7475">hana::length</a>), sequences);</div><div class="line"></div><div class="line"> static_assert(grouped == hana::make_tuple(</div><div class="line"> hana::make_tuple(</div><div class="line"> hana::make_tuple(1, 2, 3),</div><div class="line"> hana::make_tuple(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>, <span class="charliteral">&#39;z&#39;</span>)</div><div class="line"> ),</div><div class="line"> hana::make_tuple(</div><div class="line"> hana::range_c&lt;long, 0, 1&gt;</div><div class="line"> ),</div><div class="line"> hana::make_tuple(</div><div class="line"> hana::tuple_t&lt;char, int&gt;,</div><div class="line"> hana::range_c&lt;int, 0, 2&gt;,</div><div class="line"> hana::make_tuple(123.4, <span class="keyword">nullptr</span>)</div><div class="line"> )</div><div class="line"> ), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment -->
  197. </div>
  198. </div>
  199. <a id="gacaf1ebea6b3ab96ac9dcb82f0e64e547"></a>
  200. <h2 class="memtitle"><span class="permalink"><a href="#gacaf1ebea6b3ab96ac9dcb82f0e64e547">&#9670;&nbsp;</a></span>equal</h2>
  201. <div class="memitem">
  202. <div class="memproto">
  203. <table class="memname">
  204. <tr>
  205. <td class="memname">constexpr auto boost::hana::equal</td>
  206. </tr>
  207. </table>
  208. </div><div class="memdoc">
  209. <p><code>#include &lt;<a class="el" href="fwd_2equal_8hpp.html">boost/hana/fwd/equal.hpp</a>&gt;</code></p>
  210. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  211. <p>Returns a <code>Logical</code> representing whether <code>x</code> is equal to <code>y</code>.The <code>equal</code> function can be called in two different ways. First, it can be called like a normal function: </p>
  212. <div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div></div><!-- fragment --><p>However, it may also be partially applied to an argument by using <code>equal.to</code>: </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>.to(x)(y) == <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">equal</a>(x, y)</div></div><!-- fragment --><p>In other words, <code>equal.to(x)</code> is a function object that is equivalent to <code>partial(equal, x)</code>. This is provided to enhance the readability of some constructs, especially when using higher order algorithms.</p>
  213. <h2>Signature </h2>
  214. <p>Given a Logical <code>Bool</code> and two Comparables <code>A</code> and <code>B</code> that share a common embedding, the signature is \( \mathtt{equal} : A \times B \to Bool \).</p>
  215. <dl class="params"><dt>Parameters</dt><dd>
  216. <table class="params">
  217. <tr><td class="paramname">x,y</td><td>Two objects to compare for equality.</td></tr>
  218. </table>
  219. </dd>
  220. </dl>
  221. <h2>Example </h2>
  222. <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="any__of_8hpp.html">boost/hana/any_of.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&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="keywordtype">int</span> main() {</div><div class="line"> static_assert(<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(hana::make_tuple(1, 2), hana::make_tuple(1, 2)), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"> static_assert(!<a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>), <span class="stringliteral">&quot;&quot;</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>(hana::make_tuple(1, 2), <span class="charliteral">&#39;y&#39;</span>));</div><div class="line"></div><div class="line"> static_assert(<a class="code" href="group__group-Searchable.html#ga5f7ff0125c448983e1b96c3ffb84f646">hana::any_of</a>(hana::make_tuple(1, 2, 3), <a class="code" href="group__group-Comparable.html#gacaf1ebea6b3ab96ac9dcb82f0e64e547">hana::equal</a>.<a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>(2)), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment --><blockquote class="doxtable">
  223. <h4>Rationale for the arity of <code>equal</code></h4>
  224. <p>It is a valid question whether <code>equal</code> should accept more than 2 arguments and have semantics matching those of Python's <code>==</code>. This is not supported right now for the following reasons:</p><ul>
  225. <li>It was implemented in the MPL11, but it was not shown to be useful so far.</li>
  226. <li>It does not make sense for <code>not_equal</code> to have an arity of more than 2, only <code>equal</code> could maybe have those semantics, which would break symmetry.</li>
  227. </ul>
  228. </blockquote>
  229. </div>
  230. </div>
  231. <a id="gae33be2e0d5e04f19082f4b7740dfc9cd"></a>
  232. <h2 class="memtitle"><span class="permalink"><a href="#gae33be2e0d5e04f19082f4b7740dfc9cd">&#9670;&nbsp;</a></span>not_equal</h2>
  233. <div class="memitem">
  234. <div class="memproto">
  235. <table class="memname">
  236. <tr>
  237. <td class="memname">constexpr auto boost::hana::not_equal</td>
  238. </tr>
  239. </table>
  240. </div><div class="memdoc">
  241. <p><code>#include &lt;<a class="el" href="fwd_2not__equal_8hpp.html">boost/hana/fwd/not_equal.hpp</a>&gt;</code></p>
  242. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  243. <p>Returns a <code>Logical</code> representing whether <code>x</code> is not equal to <code>y</code>.The <code>not_equal</code> function can be called in two different ways. First, it can be called like a normal function: </p>
  244. <div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y)</div></div><!-- fragment --><p>However, it may also be partially applied to an argument by using <code>not_equal.to</code>: </p><div class="fragment"><div class="line"><a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>.to(x)(y) == <a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">not_equal</a>(x, y)</div></div><!-- fragment --><p>In other words, <code>not_equal.to(x)</code> is a function object that is equivalent to <code>partial(not_equal, x)</code>. This is provided to enhance the readability of some constructs, especially when using higher order algorithms.</p>
  245. <h2>Signature </h2>
  246. <p>Given a Logical <code>Bool</code> and two Comparables <code>A</code> and <code>B</code> that share a common embedding, the signature is \( \mathtt{not\_equal} : A \times B \to Bool \).</p>
  247. <dl class="params"><dt>Parameters</dt><dd>
  248. <table class="params">
  249. <tr><td class="paramname">x,y</td><td>Two objects to compare for inequality.</td></tr>
  250. </table>
  251. </dd>
  252. </dl>
  253. <h2>Example </h2>
  254. <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="all__of_8hpp.html">boost/hana/all_of.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="not__equal_8hpp.html">boost/hana/not_equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="tuple_8hpp.html">boost/hana/tuple.hpp</a>&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="keywordtype">int</span> main() {</div><div class="line"> static_assert(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(hana::make_tuple(1, 2), hana::make_tuple(3)), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line"> static_assert(<a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(<span class="charliteral">&#39;x&#39;</span>, <span class="charliteral">&#39;y&#39;</span>), <span class="stringliteral">&quot;&quot;</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#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>(hana::make_tuple(1, 2), <span class="charliteral">&#39;y&#39;</span>));</div><div class="line"></div><div class="line"> static_assert(<a class="code" href="group__group-Searchable.html#ga3a168950082f38afd9edf256f336c8ba">hana::all_of</a>(hana::make_tuple(1, 2, 3), <a class="code" href="group__group-Comparable.html#gae33be2e0d5e04f19082f4b7740dfc9cd">hana::not_equal</a>.<a class="code" href="group__group-core.html#gadc70755c1d059139297814fb3bfeb91e">to</a>(5)), <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment -->
  255. </div>
  256. </div>
  257. </div><!-- contents -->
  258. </div><!-- doc-content -->
  259. <!--
  260. Copyright Louis Dionne 2013-2017
  261. Distributed under the Boost Software License, Version 1.0.
  262. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  263. -->
  264. <!-- boost-no-inspect -->
  265. <!-- HTML footer for doxygen 1.8.9.1-->
  266. <!-- start footer part -->
  267. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  268. <ul>
  269. </ul>
  270. </div>
  271. </body>
  272. </html>