mirror of
https://github.com/boostorg/optional.git
synced 2025-07-15 21:32:17 +02:00
Added limited emplace() for older compilers
This commit is contained in:
@ -53,13 +53,15 @@
|
||||
<code class="computeroutput"><span class="identifier">optional</span></code>'s default constructor
|
||||
creates an uninitialized optional. No call to <code class="computeroutput"><span class="identifier">Resource</span></code>'s
|
||||
default constructor is attempted. <code class="computeroutput"><span class="identifier">Resource</span></code>
|
||||
doesn't have to be <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html" target="_top">Default
|
||||
Constructible</a>. In function <code class="computeroutput"><span class="identifier">getResource</span></code>
|
||||
we first check if <code class="computeroutput"><span class="identifier">resource_</span></code>
|
||||
is initialized. This time we do not use the contextual conversion to <code class="computeroutput"><span class="keyword">bool</span></code>, but a comparison with <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>. These two ways are equivalent. Function
|
||||
<code class="computeroutput"><span class="identifier">emplace</span></code> initializes the optional
|
||||
in-place by perfect-forwarding the arguments to the constructor of <code class="computeroutput"><span class="identifier">Resource</span></code>. No copy- or move-construction
|
||||
is involved here. <code class="computeroutput"><span class="identifier">Resource</span></code>
|
||||
doesn't have to be <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html" target="_top"><code class="computeroutput"><span class="identifier">DefaultConstructible</span></code></a>. In function
|
||||
<code class="computeroutput"><span class="identifier">getResource</span></code> we first check
|
||||
if <code class="computeroutput"><span class="identifier">resource_</span></code> is initialized.
|
||||
This time we do not use the contextual conversion to <code class="computeroutput"><span class="keyword">bool</span></code>,
|
||||
but a comparison with <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span></code>.
|
||||
These two ways are equivalent. Function <code class="computeroutput"><span class="identifier">emplace</span></code>
|
||||
initializes the optional in-place by perfect-forwarding the arguments to
|
||||
the constructor of <code class="computeroutput"><span class="identifier">Resource</span></code>.
|
||||
No copy- or move-construction is involved here. <code class="computeroutput"><span class="identifier">Resource</span></code>
|
||||
doesn't even have to be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
</p>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
|
Reference in New Issue
Block a user