forked from mpusz/mp-units
41 lines
16 KiB
HTML
41 lines
16 KiB
HTML
<!DOCTYPE html><html lang='en'><head><title>[qty.rep.traits]</title><meta charset='UTF-8'/><link rel='stylesheet' type='text/css' href='14882.css'/><link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css2?family=Noto+Serif'/><link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css2?family=Noto+Sans'/><link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css2?family=Noto+Sans+Mono'/><link rel='icon' href='icon.png'/><link rel='stylesheet' type='text/css' href='expanded.css' title='Normal'/><link rel='alternate stylesheet' type='text/css' href='colored.css' title='Notes and examples colored'/><link rel='alternate stylesheet' type='text/css' href='normative-only.css' title='Notes and examples hidden'/></head><body><div class='wrapper'><h1 ><a class='secnum' style='min-width:50pt'>5</a> Quantities and units library <a class='abbr_ref' href='index.html#quantities'>[quantities]</a></h1><h2 ><a class='secnum' style='min-width:65pt'>5.5</a> Representation <a class='abbr_ref' href='qty.rep.html#traits'>[qty.rep]</a></h2><h3 ><a class='secnum' style='min-width:80pt'>5.5.2</a> Traits <a class='abbr_ref'>[qty.rep.traits]</a></h3><div id='qty.fp.traits' class='section'><h4 ><a class='secnum' href='#qty.fp.traits' style='min-width:95pt'>5.5.2.1</a> Floating-point <a class='abbr_ref' href='qty.fp.traits.html'>[qty.fp.traits]</a></h4><div class='texpara'><div class='itemdecl' id='qty.fp.traits-itemdecl:1'><div class='marginalizedparent'><a class='itemDeclLink' href='#qty.fp.traits-itemdecl:1'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>struct</span> <span class='texttt'><i >actual-value-type</i></span> <span class='operator'>:</span> <span class='texttt'><i >cond-value-type</i></span><span class='anglebracket'><</span>T<span class='anglebracket'>></span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>; <span class='comment'>// see <a href="https://wg21.link/readable.traits">N4971, [readable.traits]</a></span>
|
|
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>requires</span><span class='parenthesis'>(</span><span class='operator'>!</span>std<span class='operator'>::</span>is_pointer_v<span class='anglebracket'><</span>T<span class='anglebracket'>></span> <span class='operator'>&</span><span class='operator'>&</span> <span class='operator'>!</span>std<span class='operator'>::</span>is_array_v<span class='anglebracket'><</span>T<span class='anglebracket'>></span><span class='parenthesis'>)</span> <span class='operator'>&</span><span class='operator'>&</span>
|
|
<span class='keyword'>requires</span> <span class='curlybracket'>{</span> <span class='keyword'>typename</span> std<span class='operator'>::</span>indirectly_readable_traits<span class='anglebracket'><</span>T<span class='anglebracket'>></span><span class='operator'>::</span>value_type; <span class='curlybracket'>}</span>
|
|
<span class='keyword'>struct</span> <span class='texttt'><i >actual-value-type</i></span><span class='anglebracket'><</span>T<span class='anglebracket'>></span> <span class='operator'>:</span> std<span class='operator'>::</span>indirectly_readable_traits<span class='anglebracket'><</span>T<span class='anglebracket'>></span> <span class='curlybracket'>{</span><span class='curlybracket'>}</span>;
|
|
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>using</span> <span class='texttt'><i >actual-value-type-t</i></span> <span class='operator'>=</span> <span class='texttt'><i >actual-value-type</i></span><span class='anglebracket'><</span>T<span class='anglebracket'>></span><span class='operator'>::</span>value_type;
|
|
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> Rep<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> <span class='keyword'>bool</span> <span id='lib:treat_as_floating_point'><a class='hidden_link' href='#lib:treat_as_floating_point' title='5.5.2.1 Floating-point [qty.fp.traits]'>treat_as_floating_point</a></span> <span class='operator'>=</span>
|
|
std<span class='operator'>::</span>chrono<span class='operator'>::</span>treat_as_floating_point_v<span class='anglebracket'><</span><span class='texttt'><i >actual-value-type-t</i></span><span class='anglebracket'><</span>Rep<span class='anglebracket'>></span><span class='anglebracket'>></span>;
|
|
</code></div></div><div class='para' id='qty.fp.traits-1'><div class='marginalizedparent'><a class='marginalized' href='#qty.fp.traits-1'>1</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3708'>#</a></div><div class='texpara'><div id='qty.fp.traits-1.sentence-1' class='sentence'><span class='texttt'>quantity</span> and <span class='texttt'>quantity_<span class='shy'></span>point</span> use <span class='texttt'>treat_<span class='shy'></span>as_<span class='shy'></span>floating_<span class='shy'></span>point</span>
|
|
to help determine whether implicit conversions are allowed among them<a class='hidden_link' href='#qty.fp.traits-1.sentence-1'>.</a></div></div></div></div><div class='para' id='qty.fp.traits-2'><div class='marginalizedparent'><a class='marginalized' href='#qty.fp.traits-2'>2</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3712'>#</a></div><div class='texpara'><div id='qty.fp.traits-2.sentence-1' class='sentence'><i >Remarks</i>: Pursuant to <a href="https://wg21.link/namespace.std">N4971, [namespace.std]</a> (<a href='spec.ext.html' title='4.1 External'>[spec.<span class='shy'></span>ext]</a>),
|
|
users may specialize <span class='texttt'>treat_<span class='shy'></span>as_<span class='shy'></span>floating_<span class='shy'></span>point</span>
|
|
for cv-unqualified program-defined types<a class='hidden_link' href='#qty.fp.traits-2.sentence-1'>.</a></div> <div id='qty.fp.traits-2.sentence-2' class='sentence'>Such specializations shall be usable in constant expressions (<a href="https://wg21.link/expr.const">N4971, [expr.const]</a>)
|
|
and have type <span class='texttt'><span class='keyword'>const</span> <span class='keyword'>bool</span></span><a class='hidden_link' href='#qty.fp.traits-2.sentence-2'>.</a></div></div></div></div></div><div id='qty.char.traits' class='section'><h4 ><a class='secnum' href='#qty.char.traits' style='min-width:95pt'>5.5.2.2</a> Quantity character <a class='abbr_ref' href='qty.char.traits.html'>[qty.char.traits]</a></h4><div class='texpara'><div id='lib:disable_vector'><div id='lib:disable_complex'><div id='lib:disable_scalar'><div class='itemdecl'><div class='marginalizedparent'><a class='itemDeclLink' href='#lib:disable_scalar'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> <span class='keyword'>bool</span> disable_scalar <span class='operator'>=</span> <span class='literal'>false</span>;
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> <span class='keyword'>bool</span> disable_complex <span class='operator'>=</span> <span class='literal'>false</span>;
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> T<span class='anglebracket'>></span>
|
|
<span class='keyword'>constexpr</span> <span class='keyword'>bool</span> disable_vector <span class='operator'>=</span> <span class='literal'>false</span>;
|
|
</code></div></div></div></div></div><div class='para' id='qty.char.traits-1'><div class='marginalizedparent'><a class='marginalized' href='#qty.char.traits-1'>1</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3736'>#</a></div><div class='texpara'><div id='qty.char.traits-1.sentence-1' class='sentence'>Some quantities are defined as having a numerical value (<a href="https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=112-01-29">IEC 60050, 112-01-29</a>) of a specific set (<a href="https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=102-01-02">IEC 60050, 102-01-02</a>)<a class='hidden_link' href='#qty.char.traits-1.sentence-1'>.</a></div> <div id='qty.char.traits-1.sentence-2' class='sentence'>The representation concepts use these traits
|
|
to help determine the sets <span class='texttt'>T</span> represents<a class='hidden_link' href='#qty.char.traits-1.sentence-2'>.</a></div></div></div></div><div class='para' id='qty.char.traits-2'><div class='marginalizedparent'><a class='marginalized' href='#qty.char.traits-2'>2</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3741'>#</a></div><div class='texpara'><div id='qty.char.traits-2.sentence-1' class='sentence'><i >Remarks</i>: Pursuant to <a href="https://wg21.link/namespace.std">N4971, [namespace.std]</a> (<a href='spec.ext.html' title='4.1 External'>[spec.<span class='shy'></span>ext]</a>),
|
|
users may specialize these templates
|
|
for cv-unqualified program-defined types<a class='hidden_link' href='#qty.char.traits-2.sentence-1'>.</a></div> <div id='qty.char.traits-2.sentence-2' class='sentence'>Such specializations shall be usable in constant expressions (<a href="https://wg21.link/expr.const">N4971, [expr.const]</a>)
|
|
and have type <span class='texttt'><span class='keyword'>const</span> <span class='keyword'>bool</span></span><a class='hidden_link' href='#qty.char.traits-2.sentence-2'>.</a></div></div></div></div><div class='para nonNormativeOnly' id='qty.char.traits-3'><div class='marginalizedparent'><a class='marginalized' href='#qty.char.traits-3'>3</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3749'>#</a></div><div class='texpara'><div id='qty.char.traits-note-1' class='note'><div class='texpara'>[<i>Note <a href='#qty.char.traits-note-1'>1</a></i>: <div id='qty.char.traits-3.sentence-1' class='sentence'>These templates prevent use of representation types with the library
|
|
that satisfy but do not in fact model their corresponding concept<a class='hidden_link' href='#qty.char.traits-3.sentence-1'>.</a></div> — <i>end note</i>]</div></div></div></div></div></div><div id='qty.val.traits' class='section'><h4 ><a class='secnum' href='#qty.val.traits' style='min-width:95pt'>5.5.2.3</a> Values <a class='abbr_ref' href='qty.val.traits.html'>[qty.val.traits]</a></h4><div class='para' id='qty.val.traits-1'><div class='marginalizedparent'><a class='marginalized' href='#qty.val.traits-1'>1</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3758'>#</a></div><div class='texpara'><div id='qty.val.traits-1.sentence-1' class='sentence'><span class='texttt'>quantity</span> and <span class='texttt'>quantity_<span class='shy'></span>point</span> use <span class='texttt'>representation_<span class='shy'></span>values</span>
|
|
to construct special values of its representation type<a class='hidden_link' href='#qty.val.traits-1.sentence-1'>.</a></div></div><div class='texpara'><span class='codeblock'><span class='keyword'>namespace</span> mp_units <span class='curlybracket'>{</span>
|
|
|
|
<span class='keyword'>template</span><span class='anglebracket'><</span><span class='keyword'>typename</span> Rep<span class='anglebracket'>></span>
|
|
<span class='keyword'>struct</span> <span id='lib:representation_values'><a class='hidden_link' href='#lib:representation_values' title='5.5.2.3 Values [qty.val.traits]'>representation_values</a></span> <span class='operator'>:</span> std<span class='operator'>::</span>chrono<span class='operator'>::</span>duration_values<span class='anglebracket'><</span>Rep<span class='anglebracket'>></span> <span class='curlybracket'>{</span>
|
|
<span class='keyword'>static</span> <span class='keyword'>constexpr</span> Rep one<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
<span class='curlybracket'>}</span>;
|
|
|
|
<span class='curlybracket'>}</span>
|
|
</span></div></div><div class='para' id='qty.val.traits-2'><div class='marginalizedparent'><a class='marginalized' href='#qty.val.traits-2'>2</a></div><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3773'>#</a></div><div class='texpara'><div id='qty.val.traits-2.sentence-1' class='sentence'>The requirements on <span class='texttt'>std<span class='operator'>​::​</span>chrono<span class='operator'>​::​</span>duration_<span class='shy'></span>values<span class='anglebracket'><</span>Rep<span class='anglebracket'>></span></span> (<a href="https://wg21.link/time.traits.duration.values">N4971, [time.traits.duration.values]</a>)
|
|
also apply to <span class='texttt'>representation_<span class='shy'></span>values<span class='anglebracket'><</span>Rep<span class='anglebracket'>></span></span><a class='hidden_link' href='#qty.val.traits-2.sentence-1'>.</a></div></div></div><div class='texpara'><div class='itemdecl' id='qty.val.traits-itemdecl:1'><div class='marginalizedparent'><a class='itemDeclLink' href='#qty.val.traits-itemdecl:1'>🔗</a></div><code class='itemdeclcode'><span class='keyword'>static</span> <span class='keyword'>constexpr</span> Rep one<span class='parenthesis'>(</span><span class='parenthesis'>)</span> <span class='keyword'>noexcept</span>;
|
|
</code></div></div><div class='para' id='qty.val.traits-3'><div class='marginalizedparent'><a class='marginalized' href='#qty.val.traits-3'>3</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3782'>#</a></div><div class='texpara'><div id='qty.val.traits-3.sentence-1' class='sentence'><i >Returns</i>: <span class='texttt'>Rep<span class='parenthesis'>(</span><span class='literal'>1</span><span class='parenthesis'>)</span></span><a class='hidden_link' href='#qty.val.traits-3.sentence-1'>.</a></div></div></div></div><div class='para' id='qty.val.traits-4'><div class='marginalizedparent'><a class='marginalized' href='#qty.val.traits-4'>4</a></div><div class='itemdescr'><div class='sourceLinkParent'><a class='sourceLink' href='https://github.com/mpusz/mp-unitse9c5f7236ebfe1b287a5a4a49aaf57fbefa87233/source/quantities.tex#L3786'>#</a></div><div class='texpara'><div id='qty.val.traits-4.sentence-1' class='sentence'><i >Remarks</i>: The value returned shall be the neutral element for multiplication (<a href="https://www.electropedia.org/iev/iev.nsf/display?openform&ievref=102-01-19">IEC 60050, 102-01-19</a>)<a class='hidden_link' href='#qty.val.traits-4.sentence-1'>.</a></div></div></div></div></div></div></body></html> |