mirror of
https://github.com/boostorg/optional.git
synced 2025-07-29 03:57:20 +02:00
docs -- expanded tutprial section
This commit is contained in:
@ -44,10 +44,10 @@
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">begin</span><span class="special">,</span> <span class="identifier">end</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">getPeriod</span><span class="special">();</span>
|
||||
</pre>
|
||||
<p>
|
||||
The second line works already, this is the capability of Boost.Tuple library,
|
||||
but the first line won't work. We could set some invented initial dates,
|
||||
but it is confusing and may be an unacceptable cost, given that these values
|
||||
will be overwritten in the next line anyway. This is where <code class="computeroutput"><span class="identifier">optional</span></code> can help:
|
||||
The second line works already, this is the capability of <a href="../../../../../tuple/index.html" target="_top">Boost.Tuple</a>
|
||||
library, but the first line won't work. We could set some invented initial
|
||||
dates, but it is confusing and may be an unacceptable cost, given that these
|
||||
values will be overwritten in the next line anyway. This is where <code class="computeroutput"><span class="identifier">optional</span></code> can help:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="identifier">Date</span><span class="special">></span> <span class="identifier">begin</span><span class="special">,</span> <span class="identifier">end</span><span class="special">;</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">tie</span><span class="special">(</span><span class="identifier">begin</span><span class="special">,</span> <span class="identifier">end</span><span class="special">)</span> <span class="special">=</span> <span class="identifier">getPeriod</span><span class="special">();</span>
|
||||
|
@ -43,14 +43,9 @@
|
||||
</pre>
|
||||
<p>
|
||||
This works because <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>
|
||||
is <code class="computeroutput"><span class="identifier">LessThanComparable</span></code> whenever
|
||||
<code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">LessThanComparable</span></code>.
|
||||
In this case the state of being uninitialized is treated as a yet another
|
||||
value of <code class="computeroutput"><span class="identifier">T</span></code>, which is compared
|
||||
less than any value of <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
So the set of values that type <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>
|
||||
can assume is {<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>, -2147483648, -2147483647, ..., -1,
|
||||
0, 1, ..., 2147483647} (assuming a 32-bit <code class="computeroutput"><span class="keyword">int</span></code>).
|
||||
is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a> whenever <code class="computeroutput"><span class="identifier">T</span></code> is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html" target="_top"><code class="computeroutput"><span class="identifier">LessThanComparable</span></code></a>. In this case
|
||||
the state of being uninitialized is treated as a yet another value of <code class="computeroutput"><span class="identifier">T</span></code>, which is compared less than any value
|
||||
of <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
|
Reference in New Issue
Block a user