<!DOCTYPE html><htmllang='en'><head><title>[qty.assign.ops]</title><metacharset='UTF-8'/><linkrel='stylesheet'type='text/css'href='14882.css'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Serif'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans'/><linkrel='stylesheet'type='text/css'href='https://fonts.googleapis.com/css2?family=Noto+Sans+Mono'/><linkrel='icon'href='icon.png'/><linkrel='stylesheet'type='text/css'href='expanded.css'title='Normal'/><linkrel='alternate stylesheet'type='text/css'href='colored.css'title='Notes and examples colored'/><linkrel='alternate stylesheet'type='text/css'href='normative-only.css'title='Notes and examples hidden'/></head><body><divclass='wrapper'><h1><aclass='secnum'style='min-width:50pt'>5</a> Quantities and units library <aclass='abbr_ref'href='index.html#quantities'>[quantities]</a></h1><h2><aclass='secnum'style='min-width:65pt'>5.6</a> Quantity <aclass='abbr_ref'href='qty.html#assign.ops'>[qty]</a></h2><h3><aclass='secnum'style='min-width:80pt'>5.6.10</a> Compound assignment operations <aclass='abbr_ref'>[qty.assign.ops]</a></h3><divclass='para'id='1'><divclass='marginalizedparent'><aclass='marginalized'href='#1'>1</a></div><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4862'>#</a></div><divclass='texpara'><divid='1.sentence-1'class='sentence'>In the following descriptions,
let <spanclass='texttt'>@</span> be the <spanclass='textsf'><i>operator</i></span><aclass='hidden_link'href='#1.sentence-1'>.</a></div></div></div><divclass='texpara'><divid='lib:quantity,operator%='><divid='lib:operator%=,quantity'><divid='lib:quantity,operator-='><divid='lib:operator-=,quantity'><divid='lib:quantity,operator+='><divid='lib:operator+=,quantity'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator+=,quantity'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><aclass='index'id='conceptref:Mutable'></a><spanclass='texttt'><i>Mutable</i></span><spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <spanclass='keyword'>auto</span> R2, <spanclass='keyword'>typename</span> Rep2<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div></div></div><divclass='para'id='2'><divclass='marginalizedparent'><aclass='marginalized'href='#2'>2</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4882'>#</a></div><divclass='texpara'><divid='2.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>%</span><spanclass='operator'>=</span></span>, then <spanclass='texttt'>is_<spanclass='shy'></span>neq_<spanclass='shy'></span>zero<spanclass='parenthesis'>(</span>rhs<spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#2.sentence-1'>.</a></div></div></div></div><divclass='para'id='3'><divclass='marginalizedparent'><aclass='marginalized'href='#3'>3</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4886'>#</a></div><divclass='texpara'><divid='3.sentence-1'class='sentence'><i>Effects</i>: Equivalent to
<spanclass='texttt'>lhs<spanclass='operator'>.</span><spanclass='texttt'><i>numerical-value</i></span> @ rhs<spanclass='operator'>.</span>in<spanclass='parenthesis'>(</span>lhs<spanclass='operator'>.</span>unit<spanclass='parenthesis'>)</span><spanclass='operator'>.</span><spanclass='texttt'><i>numerical-value</i></span></span><aclass='hidden_link'href='#3.sentence-1'>.</a></div></div></div></div><divclass='para'id='4'><divclass='marginalizedparent'><aclass='marginalized'href='#4'>4</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4891'>#</a></div><divclass='texpara'><divid='4.sentence-1'class='sentence'><i>Returns</i>: <spanclass='texttt'>std<spanclass='operator'>​::​</span>forward<spanclass='anglebracket'><</span>Q<spanclass='anglebracket'>></span><spanclass='parenthesis'>(</span>lhs<spanclass='parenthesis'>)</span></span><aclass='hidden_link'href='#4.sentence-1'>.</a></div></div></div></div><divclass='para'id='5'><divclass='marginalizedparent'><aclass='marginalized'href='#5'>5</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4895'>#</a></div><divclass='texpara'><divid='5.sentence-1'class='sentence'><i>Remarks</i>: Let <i>C</i> be
<ulclass='itemize'><liid='5.1'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#5.1'>(5.1)</a></div><spanclass='texttt'><spanclass='parenthesis'>(</span><spanclass='operator'>!</span>treat_<spanclass='shy'></span>as_<spanclass='shy'></span>floating_<spanclass='shy'></span>point<spanclass='anglebracket'><</span>rep<spanclass='anglebracket'>></span><spanclass='parenthesis'>)</span></span> if <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>%</span><spanclass='operator'>=</span></span>, and</li><liid='5.2'><divclass='marginalizedparent'style='left:-39mm'><aclass='marginalized'href='#5.2'>(5.2)</a></div><spanclass='texttt'><spanclass='literal'>true</span></span> otherwise<aclass='hidden_link'href='#5.sentence-1'>.</a></li></ul></div><divid='5.sentence-2'class='sentence'>
The expression in the <spanclass='textsf'><i>requires-clause</i></span> is equivalent to:
<spanclass='keyword'>requires</span><spanclass='parenthesis'>(</span>rep<spanclass='operator'>&</span> a, <spanclass='keyword'>const</span> Rep2 b<spanclass='parenthesis'>)</span><spanclass='curlybracket'>{</span>
<spanclass='curlybracket'>{</span> a @ b <spanclass='curlybracket'>}</span><spanclass='operator'>-</span><spanclass='anglebracket'>></span> std<spanclass='operator'>::</span>same_as<spanclass='anglebracket'><</span>rep<spanclass='operator'>&</span><spanclass='anglebracket'>></span>;
</span></div></div></div></div><divclass='para'id='6'><divclass='marginalizedparent'><aclass='marginalized'href='#6'>6</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4912'>#</a></div><divclass='texpara'><divid='6.sentence-1'class='sentence'><i>Recommended practice</i>: If <spanclass='texttt'>equivalent<spanclass='parenthesis'>(</span>unit, get_<spanclass='shy'></span>unit<spanclass='parenthesis'>(</span>rhs<spanclass='operator'>.</span>reference<spanclass='parenthesis'>)</span><spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span>,
then the expression <spanclass='texttt'>rhs<spanclass='operator'>.</span>in<spanclass='parenthesis'>(</span>lhs<spanclass='operator'>.</span>unit<spanclass='parenthesis'>)</span></span> is replaced with <spanclass='texttt'>rhs</span><aclass='hidden_link'href='#6.sentence-1'>.</a></div></div></div></div><divclass='texpara'><divid='lib:quantity,operator/='><divid='lib:operator/=,quantity'><divid='lib:quantity,operator*='><divid='lib:operator*=,quantity'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator*=,quantity'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><aclass='index'id='conceptref:Mutable___'></a><spanclass='texttt'><i>Mutable</i></span><spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <aclass='index'id='conceptref:ValuePreservingTo'></a><spanclass='texttt'><i>ValuePreservingTo</i></span><spanclass='anglebracket'><</span>Rep<spanclass='anglebracket'>></span> Value<spanclass='anglebracket'>></span>
<spanclass='keyword'>template</span><spanclass='anglebracket'><</span><aclass='index'id='conceptref:Mutable____'></a><spanclass='texttt'><i>Mutable</i></span><spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <aclass='index'id='conceptref:ValuePreservingTo_'></a><spanclass='texttt'><i>ValuePreservingTo</i></span><spanclass='anglebracket'><</span>Rep<spanclass='anglebracket'>></span> Value<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div><divclass='para'id='7'><divclass='marginalizedparent'><aclass='marginalized'href='#7'>7</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4930'>#</a></div><divclass='texpara'><divid='7.sentence-1'class='sentence'><i>Preconditions</i>: If <spanclass='texttt'>@</span> is <spanclass='texttt'><spanclass='operator'>/</span><spanclass='operator'>=</span></span>, then <spanclass='texttt'>rhs <spanclass='operator'>!</span><spanclass='operator'>=</span> representation_<spanclass='shy'></span>values<spanclass='anglebracket'><</span>Value<spanclass='anglebracket'>></span><spanclass='operator'>​::​</span>zero<spanclass='parenthesis'>(</span><spanclass='parenthesis'>)</span></span> is <spanclass='texttt'><spanclass='literal'>true</span></span><aclass='hidden_link'href='#7.sentence-1'>.</a></div></div></div></div><divclass='para'id='8'><divclass='marginalizedparent'><aclass='marginalized'href='#8'>8</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4934'>#</a></div><divclass='texpara'><divid='8.sentence-1'class='sentence'><i>Effects</i>: Equivalent to
<spanclass='texttt'>lhs<spanclass='operator'>.</span><spanclass='texttt'><i>numerical-value</i></span> @ rhs</span><aclass='hidden_link'href='#8.sentence-1'>.</a></div></div></div></div><divclass='para'id='9'><divclass='marginalizedparent'><aclass='marginalized'href='#9'>9</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4939'>#</a></div><divclass='texpara'><divid='9.sentence-1'class='sentence'><i>Returns</i>: <spanclass='texttt'>std<spanclass='operator'>​::​</span>forward<spanclass='anglebracket'><</span>Q<spanclass='anglebracket'>></span><spanclass='parenthesis'>(</span>lhs<spanclass='parenthesis'>)</span></span><aclass='hidden_link'href='#9.sentence-1'>.</a></div></div></div></div><divclass='para'id='10'><divclass='marginalizedparent'><aclass='marginalized'href='#10'>10</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4943'>#</a></div><divclass='texpara'><divid='10.sentence-1'class='sentence'><i>Remarks</i>: The expression in the <spanclass='textsf'><i>requires-clause</i></span> is equivalent to:
<spanclass='codeblock'><spanclass='parenthesis'>(</span><spanclass='operator'>!</span><ahref='qty.syn.html#concept:Quantity'title='5.6.3 Class template quantity [qty.syn]'><spanid='conceptref:Quantity'><spanclass='tcode_in_codeblock'>Quantity</span></span></a><spanclass='anglebracket'><</span>Value<spanclass='anglebracket'>></span><spanclass='parenthesis'>)</span><spanclass='operator'>&</span><spanclass='operator'>&</span><spanclass='keyword'>requires</span><spanclass='parenthesis'>(</span>rep<spanclass='operator'>&</span> a, <spanclass='keyword'>const</span> Value b<spanclass='parenthesis'>)</span><spanclass='curlybracket'>{</span>
<spanclass='curlybracket'>{</span> a @ b <spanclass='curlybracket'>}</span><spanclass='operator'>-</span><spanclass='anglebracket'>></span> std<spanclass='operator'>::</span>same_as<spanclass='anglebracket'><</span>rep<spanclass='operator'>&</span><spanclass='anglebracket'>></span>;
<spanclass='curlybracket'>}</span>
</span></div></div></div></div><divclass='texpara'><divid='lib:quantity,operator/=_'><divid='lib:operator/=,quantity_'><divid='lib:quantity,operator*=_'><divid='lib:operator*=,quantity_'><divclass='itemdecl'><divclass='marginalizedparent'><aclass='itemDeclLink'href='#lib:operator*=,quantity_'>🔗</a></div><codeclass='itemdeclcode'><spanclass='keyword'>template</span><spanclass='anglebracket'><</span><aclass='index'id='conceptref:Mutable_____'></a><spanclass='texttt'><i>Mutable</i></span><spanclass='anglebracket'><</span>quantity<spanclass='anglebracket'>></span> Q, <ahref='qty.syn.html#concept:QuantityOf'title='5.6.3 Class template quantity [qty.syn]'><spanid='conceptref:QuantityOf'><spanclass='texttt'>QuantityOf</span></span></a><spanclass='anglebracket'><</span>dimensionless<spanclass='anglebracket'>></span> Q2<spanclass='anglebracket'>></span>
</code></div></div></div></div></div></div><divclass='para'id='11'><divclass='marginalizedparent'><aclass='marginalized'href='#11'>11</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4965'>#</a></div><divclass='texpara'><divid='11.sentence-1'class='sentence'><i>Effects</i>: Equivalent to:
<spanclass='texttt'><spanclass='keyword'>return</span> std<spanclass='operator'>​::​</span>forward<spanclass='anglebracket'><</span>Q<spanclass='anglebracket'>></span><spanclass='parenthesis'>(</span>lhs<spanclass='parenthesis'>)</span> @ rhs<spanclass='operator'>.</span><spanclass='texttt'><i>numerical-value</i></span>;</span></div></div></div></div><divclass='para'id='12'><divclass='marginalizedparent'><aclass='marginalized'href='#12'>12</a></div><divclass='itemdescr'><divclass='sourceLinkParent'><aclass='sourceLink'href='https://github.com/mpusz/mp-units329ffdaacb1bd7bed08565ac80d9eef7ccb1e5b5/source/quantities.tex#L4970'>#</a></div><divclass='texpara'><divid='12.sentence-1'class='sentence'><i>Remarks</i>: The expression in the <spanclass='textsf'><i>requires-clause</i></span> is equivalent to:
<spanclass='keyword'>requires</span><spanclass='parenthesis'>(</span>rep<spanclass='operator'>&</span> a, <spanclass='keyword'>const</span> Q2<spanclass='operator'>::</span>rep b<spanclass='parenthesis'>)</span><spanclass='curlybracket'>{</span>
<spanclass='curlybracket'>{</span> a @ b <spanclass='curlybracket'>}</span><spanclass='operator'>-</span><spanclass='anglebracket'>></span> std<spanclass='operator'>::</span>same_as<spanclass='anglebracket'><</span>rep<spanclass='operator'>&</span><spanclass='anglebracket'>></span>;