forked from mpusz/mp-units
43 lines
18 KiB
HTML
43 lines
18 KiB
HTML
<!DOCTYPE html><html lang='en'><head><title>[utility]</title><meta charset='UTF-8'/><link rel='stylesheet' type='text/css' href='14882.css'/><link rel='stylesheet' type='text/css' href='expanded.css' title='Notes and examples expanded'/><link rel='alternate stylesheet' type='text/css' href='colored.css' title='Notes and examples colored'/><link rel='icon' href='icon.png'/></head><body><div class='wrapper'><h1 ><a class='secnum' style='min-width:73pt'>4</a> General utilities library <a class='abbr_ref' href='./#utilities'>[utilities]</a></h1><h2 ><a class='secnum' style='min-width:88pt'>4.2</a> Utility components <a class='abbr_ref'>[utility]</a></h2><div id='syn' class='section'><h3 ><a class='secnum' href='#syn' style='min-width:103pt'>4.2.1</a> Header <span class='texttt'><jegp/utility.hpp></span> synopsis <a class='abbr_ref' href='utility.syn'>[utility.syn]</a></h3><div class='para' id='syn-1'><div class='marginalizedparent'><a class='marginalized' href='#syn-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L18'>#</a></div><div id='syn-1.sentence-1' class='sentence'>The header <span class='indexparent'><a class='index' id=':<jegp/utility.hpp>'></a></span><span class='texttt'><span class='anglebracket'><</span>jegp<span class='operator'>/</span>utility<span class='operator'>.</span>hpp<span class='anglebracket'>></span></span>
|
|
contains some basic constructs<a class='hidden_link' href='#syn-1.sentence-1'>.</a></div><span class='indexparent'><a class='index' id=':<jegp/utility.hpp>_'></a></span><pre class='codeblock'>
|
|
<span class='keyword'>namespace</span> jegp
|
|
<span class='curlybracket'>{</span>
|
|
<span class='comment'>// <a href='#underlying'>[utility.underlying]</a>, <span class='tcode_in_codeblock'>underlying</span></span>
|
|
<span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span> Enum<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> std<span class='operator'>::</span>underlying_type_t<span class='anglebracket'><</span>Enum<span class='anglebracket'>></span> underlying<span class='parenthesis'>(</span>Enum e<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
|
|
<span class='comment'>// <a href='#static.downcast'>[static.downcast]</a>, <span class='tcode_in_codeblock'>static_­downcast</span></span>
|
|
<span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span> DerivedRef, <span class='keyword'>class</span> Base<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> DerivedRef static_downcast<span class='parenthesis'>(</span>Base<span class='operator'>&</span><span class='operator'>&</span> base<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
|
|
<span class='comment'>// <a href='#hash.combine'>[hash.combine]</a>, <span class='tcode_in_codeblock'>hash_­combine</span></span>
|
|
<span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span> Args<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> std<span class='operator'>::</span>size_t hash_combine<span class='parenthesis'>(</span><span class='keyword'>const</span> Args<span class='operator'>&</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span> args<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span><span class='parenthesis'>(</span><span class='textit'><span class='texttt'>see below</span></span><span class='parenthesis'>)</span>;
|
|
|
|
<span class='curlybracket'>}</span> <span class='comment'>// namespace jegp</span>
|
|
</pre></div></div><div id='underlying' class='section'><h3 ><a class='secnum' href='#underlying' style='min-width:103pt'>4.2.2</a> <span class='texttt'>underlying</span> <a class='abbr_ref' href='utility.underlying'>[utility.underlying]</a></h3><span class='indexparent'><a class='index' id='lib:underlying'></a></span><div class='itemdecl' id='underlying-itemdecl:1'><div class='marginalizedparent'><a class='itemDeclLink' href='#underlying-itemdecl:1'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span> Enum<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> std<span class='operator'>::</span>underlying_type_t<span class='anglebracket'><</span>Enum<span class='anglebracket'>></span> underlying<span class='parenthesis'>(</span>Enum e<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
</code></div><div class='itemdescr'></div><div class='para' id='underlying-1'><div class='marginalizedparent'><a class='marginalized' href='#underlying-1'>1</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L50'>#</a></div><div id='underlying-1.sentence-1' class='sentence'><span class='textit'>Constraints:</span>
|
|
<span class='texttt'>std<span class='operator'>​::​</span>is_­enum_­v<span class='anglebracket'><</span>Enum<span class='anglebracket'>></span></span> is <span class='texttt'><span class='literal'>true</span></span><a class='hidden_link' href='#underlying-1.sentence-1'>.</a></div></div></div><div class='para' id='underlying-2'><div class='marginalizedparent'><a class='marginalized' href='#underlying-2'>2</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L54'>#</a></div><div id='underlying-2.sentence-1' class='sentence'><span class='textit'>Returns:</span>
|
|
<span class='texttt'><span class='keyword'>static_­cast</span><span class='anglebracket'><</span>std<span class='operator'>​::​</span>underlying_­type_­t<span class='anglebracket'><</span>Enum<span class='anglebracket'>></span><span class='anglebracket'>></span><span class='parenthesis'>(</span>e<span class='parenthesis'>)</span></span><a class='hidden_link' href='#underlying-2.sentence-1'>.</a></div></div></div></div><div id='static.downcast' class='section'><h3 ><a class='secnum' href='#static.downcast' style='min-width:103pt'>4.2.3</a> <span class='texttt'>static_­downcast</span> <a class='abbr_ref' href='static.downcast'>[static.downcast]</a></h3><div class='para' id='static.downcast-1'><div class='marginalizedparent'><a class='marginalized' href='#static.downcast-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L61'>#</a></div><div id='static.downcast-1.sentence-1' class='sentence'>A <span class='texttt'><span class='keyword'>static_­cast</span></span> that performs a downcast<a class='hidden_link' href='#static.downcast-1.sentence-1'>.</a></div> <span class='indexparent'><a class='index' id='lib:static_downcast'></a></span></div><div class='itemdecl' id='static.downcast-itemdecl:1'><div class='marginalizedparent'><a class='itemDeclLink' href='#static.downcast-itemdecl:1'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span> DerivedRef, <span class='keyword'>class</span> Base<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> DerivedRef static_downcast<span class='parenthesis'>(</span>Base<span class='operator'>&</span><span class='operator'>&</span> base<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
</code></div><div class='itemdescr'></div><div class='para' id='static.downcast-2'><div class='marginalizedparent'><a class='marginalized' href='#static.downcast-2'>2</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L71'>#</a></div><div id='static.downcast-2.sentence-1' class='sentence'>Let <span class='texttt'><span class='textit'>derived-ref</span></span> be
|
|
<span class='texttt'><span class='keyword'>static_­cast</span><span class='anglebracket'><</span>DerivedRef<span class='anglebracket'>></span><span class='parenthesis'>(</span>std<span class='operator'>​::​</span>forward<span class='anglebracket'><</span>Base<span class='anglebracket'>></span><span class='parenthesis'>(</span>base<span class='parenthesis'>)</span><span class='parenthesis'>)</span></span><a class='hidden_link' href='#static.downcast-2.sentence-1'>.</a></div></div></div><div class='para' id='static.downcast-3'><div class='marginalizedparent'><a class='marginalized' href='#static.downcast-3'>3</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L75'>#</a></div><div id='static.downcast-3.sentence-1' class='sentence'><span class='textit'>Constraints:</span>
|
|
<ul class='itemize'><li id='static.downcast-3.1'><div class='marginalizedparent' style='left:-10em'><a class='marginalized' href='#static.downcast-3.1'>(3.1)</a></div><span class='texttt'>DerivedRef</span> is a reference type,</li><li id='static.downcast-3.2'><div class='marginalizedparent' style='left:-10em'><a class='marginalized' href='#static.downcast-3.2'>(3.2)</a></div><span class='texttt'>std<span class='operator'>​::​</span>remove_­cvref_­t<span class='anglebracket'><</span>DerivedRef<span class='anglebracket'>></span></span> is derived from
|
|
<span class='texttt'>std<span class='operator'>​::​</span>remove_­cvref_­t<span class='anglebracket'><</span>Base<span class='anglebracket'>></span></span>, and</li><li id='static.downcast-3.3'><div class='marginalizedparent' style='left:-10em'><a class='marginalized' href='#static.downcast-3.3'>(3.3)</a></div><span class='texttt'><span class='textit'>derived-ref</span></span> is well-formed<a class='hidden_link' href='#static.downcast-3.sentence-1'>.</a></li></ul></div></div></div><div class='para' id='static.downcast-4'><div class='marginalizedparent'><a class='marginalized' href='#static.downcast-4'>4</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L87'>#</a></div><div id='static.downcast-4.sentence-1' class='sentence'><span class='textit'>Preconditions:</span>
|
|
<span class='texttt'><span class='textit'>derived-ref</span></span> has well-defined behavior<a class='hidden_link' href='#static.downcast-4.sentence-1'>.</a></div></div></div><div class='para' id='static.downcast-5'><div class='marginalizedparent'><a class='marginalized' href='#static.downcast-5'>5</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L91'>#</a></div><div id='static.downcast-5.sentence-1' class='sentence'><span class='textit'>Returns:</span>
|
|
<span class='texttt'><span class='textit'>derived-ref</span></span><a class='hidden_link' href='#static.downcast-5.sentence-1'>.</a></div></div></div></div><div id='hash.combine' class='section'><h3 ><a class='secnum' href='#hash.combine' style='min-width:103pt'>4.2.4</a> <span class='texttt'>hash_­combine</span> <a class='abbr_ref' href='hash.combine'>[hash.combine]</a></h3><div class='para' id='hash.combine-1'><div class='marginalizedparent'><a class='marginalized' href='#hash.combine-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L98'>#</a></div><div id='hash.combine-1.sentence-1' class='sentence'>Insipred by <span class='texttt'>Boost<span class='operator'>.</span>ContainerHash</span><a class='hidden_link' href='#hash.combine-1.sentence-1'>.</a></div> <div id='hash.combine-1.sentence-2' class='sentence'>Useful in the specializations of <span class='texttt'>std<span class='operator'>​::​</span>hash</span>
|
|
whose <span class='texttt'>Key</span>'s salient parts consist of two or more objects<a class='hidden_link' href='#hash.combine-1.sentence-2'>.</a></div> <span class='indexparent'><a class='index' id='lib:hash_combine'></a></span></div><div class='itemdecl' id='hash.combine-itemdecl:1'><div class='marginalizedparent'><a class='itemDeclLink' href='#hash.combine-itemdecl:1'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>template</span> <span class='anglebracket'><</span><span class='keyword'>class</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span> Args<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> std<span class='operator'>::</span>size_t hash_combine<span class='parenthesis'>(</span><span class='keyword'>const</span> Args<span class='operator'>&</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span> args<span class='parenthesis'>)</span> <span class='keyword'>noexcept</span><span class='parenthesis'>(</span><span class='textit'><span class='texttt'>see below</span></span><span class='parenthesis'>)</span>;
|
|
</code></div><div class='itemdescr'></div><div class='para' id='hash.combine-2'><div class='marginalizedparent'><a class='marginalized' href='#hash.combine-2'>2</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L110'>#</a></div><div id='hash.combine-2.sentence-1' class='sentence'><span class='textit'>Constraints:</span>
|
|
<ul class='itemize'><li id='hash.combine-2.1'><div class='marginalizedparent' style='left:-10em'><a class='marginalized' href='#hash.combine-2.1'>(2.1)</a></div><span class="mjx-chtml"><span class="mjx-math"><span class="mjx-mrow" aria-hidden="true"><span class="mjx-texatom"><span class="mjx-mrow"><span class="mjx-mtext"><span class="mjx-char MJXc-TeX-type-R" style="padding-top: 0.519em; padding-bottom: 0.519em;"><span class='keyword'>sizeof</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span><span class='parenthesis'>(</span>Args<span class='parenthesis'>)</span></span></span></span></span><span class="mjx-mo MJXc-space3"><span class="mjx-char MJXc-TeX-main-R" style="padding-top: 0.372em; padding-bottom: 0.446em;">≥</span></span><span class="mjx-texatom MJXc-space3"><span class="mjx-mrow"></span></span><span class="mjx-mn"><span class="mjx-char MJXc-TeX-main-R" style="padding-top: 0.372em; padding-bottom: 0.372em;">2</span></span></span></span></span> and</li><li id='hash.combine-2.2'><div class='marginalizedparent' style='left:-10em'><a class='marginalized' href='#hash.combine-2.2'>(2.2)</a></div><span class='texttt'>std<span class='operator'>​::​</span>hash<span class='anglebracket'><</span>T<span class='anglebracket'>></span></span> is enabled (C++ Standard's <a href="https://wg21.link/unord.hash">[unord.hash]</a>)
|
|
for all <span class='texttt'>T</span> in <span class='texttt'>Args</span><a class='hidden_link' href='#hash.combine-2.sentence-1'>.</a></li></ul></div></div></div><div class='para' id='hash.combine-3'><div class='marginalizedparent'><a class='marginalized' href='#hash.combine-3'>3</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L120'>#</a></div><div id='hash.combine-3.sentence-1' class='sentence'><span class='textit'>Effects:</span>
|
|
Equivalent to:
|
|
<pre class='codeblock'>
|
|
std<span class='operator'>::</span>size_t seed<span class='curlybracket'>{</span><span class='literal'>0</span><span class='curlybracket'>}</span>;
|
|
<span class='keyword'>return</span> <span class='parenthesis'>(</span><span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span>, <span class='parenthesis'>(</span>seed <span class='operator'>^</span><span class='operator'>=</span> std<span class='operator'>::</span>hash<span class='anglebracket'><</span>Args<span class='anglebracket'>></span><span class='curlybracket'>{</span><span class='curlybracket'>}</span><span class='parenthesis'>(</span>args<span class='parenthesis'>)</span> <span class='operator'>+</span> <span class='parenthesis'>(</span>seed <span class='anglebracket'><</span><span class='anglebracket'><</span> <span class='literal'>6</span><span class='parenthesis'>)</span> <span class='operator'>+</span> <span class='parenthesis'>(</span>seed <span class='anglebracket'>></span><span class='anglebracket'>></span> <span class='literal'>2</span><span class='parenthesis'>)</span><span class='parenthesis'>)</span><span class='parenthesis'>)</span>;
|
|
</pre></div></div></div><div class='para' id='hash.combine-4'><div class='marginalizedparent'><a class='marginalized' href='#hash.combine-4'>4</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/johelegp/jegp/tree/4dfbe8f5446ba1f53439a36ce12119fe285268c9/doc/utilities.tex#L128'>#</a></div><div id='hash.combine-4.sentence-1' class='sentence'><span class='textit'>Remarks:</span>
|
|
The expression inside <span class='texttt'><span class='keyword'>noexcept</span></span> is equivalent to
|
|
<pre class='codeblock'>
|
|
<span class='parenthesis'>(</span><span class='keyword'>noexcept</span><span class='parenthesis'>(</span>std<span class='operator'>::</span>hash<span class='anglebracket'><</span>Args<span class='anglebracket'>></span><span class='curlybracket'>{</span><span class='curlybracket'>}</span><span class='parenthesis'>(</span>args<span class='parenthesis'>)</span><span class='parenthesis'>)</span> <span class='operator'>&</span><span class='operator'>&</span> <span class='operator'>.</span><span class='operator'>.</span><span class='operator'>.</span><span class='parenthesis'>)</span>
|
|
</pre></div></div></div></div></div></body></html> |