forked from boostorg/optional
More restrictive assignment from optional<U>
This commit is contained in:
1 parent
16023fe934
commit
59266a2630
8 files changed
+444
-175
No files matched your search
+37
-42
@@ -602,10 +602,11 @@ __SPACE__
|
||||
|
||||
* [*Requires:] `T` is __COPY_CONSTRUCTIBLE__ and `CopyAssignable`.
|
||||
* [*Effects:]
|
||||
* If `!*this && !rhs` no effect, otherwise
|
||||
* if `bool(*this) && !rhs`, destroys the contained value by calling `val->T::~T()`, otherwise
|
||||
* if `!*this && bool(rhs)`, initializes the contained value as if direct-initializing an object of type `T` with `*rhs`, otherwise
|
||||
* (if `bool(*this) && bool(rhs)`) assigns `*rhs` to the contained value.
|
||||
[table
|
||||
[[][`*this` contains a value][`*this` does not contain a value]]
|
||||
[[`rhs` contains a value][assigns `*rhs` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `*rhs`]]
|
||||
[[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]]
|
||||
]
|
||||
* [*Returns:] `*this`;
|
||||
* [*Postconditions:] `bool(rhs) == bool(*this)`.
|
||||
* [*Exception Safety:] If any exception is thrown, the initialization state of `*this` and `rhs` remains unchanged.
|
||||
@@ -662,10 +663,11 @@ __SPACE__
|
||||
|
||||
* [*Requires:] `T` is __MOVE_CONSTRUCTIBLE__ and `MoveAssignable`.
|
||||
* [*Effects:]
|
||||
* If `!*this && !rhs` no effect, otherwise
|
||||
* if `bool(*this) && !rhs`, destroys the contained value by calling `val->T::~T()`, otherwise
|
||||
* if `!*this && bool(rhs)`, initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`, otherwise
|
||||
* (if `bool(*this) && bool(rhs)`) assigns `std::move(*rhs)` to the contained value.
|
||||
[table
|
||||
[[][`*this` contains a value][`*this` does not contain a value]]
|
||||
[[`rhs` contains a value][assigns `std::move(*rhs)` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`]]
|
||||
[[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]]
|
||||
]
|
||||
* [*Returns:] `*this`;
|
||||
* [*Postconditions:] `bool(rhs) == bool(*this)`.
|
||||
* [*Remarks:] The expression inside `noexcept` is equivalent to `is_nothrow_move_constructible<T>::value && is_nothrow_move_assignable<T>::value`.
|
||||
@@ -696,21 +698,17 @@ __SPACE__
|
||||
|
||||
[: `template<U> optional& optional<T` ['(not a ref)]`>::operator= ( optional<U> const& rhs ) ;`]
|
||||
|
||||
* [*Effect:] Assigns another convertible optional to an optional.
|
||||
* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and
|
||||
its value is a ['copy] of the value of `rhs` ['converted] to type `T`; else
|
||||
`*this` is uninitialized.
|
||||
* [*Throws:] Whatever `T::operator=( U const& )` or `T::T( U const& )` throws.
|
||||
* [*Notes:] If both `*this` and rhs are initially initialized, `T`'s
|
||||
['assignment operator] (from `U`) is used. If `*this` is initially initialized
|
||||
but `rhs` is uninitialized, `T`'s ['destructor] is called. If `*this` is
|
||||
initially uninitialized but rhs is initialized, `T`'s ['converting constructor]
|
||||
(from `U`) is called.
|
||||
* [*Exception Safety:] In the event of an exception, the initialization state
|
||||
of `*this` is unchanged and its value unspecified as far as optional is
|
||||
concerned (it is up to `T`'s `operator=()`). If `*this` is initially
|
||||
uninitialized and `T`'s converting constructor fails, `*this` is left properly
|
||||
uninitialized.
|
||||
* [*Effect:]
|
||||
[table
|
||||
[[][`*this` contains a value][`*this` does not contain a value]]
|
||||
[[`rhs` contains a value][assigns `*rhs` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `*rhs`]]
|
||||
[[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]]
|
||||
]
|
||||
* [*Returns:] `*this`.
|
||||
* [*Postconditions:] `bool(rhs) == bool(*this)`.
|
||||
* [*Exception Safety:] If any exception is thrown, the result of the expression `bool(*this)` remains unchanged.
|
||||
If an exception is thrown during the call to `T`'s constructor, no effect.
|
||||
If an exception is thrown during the call to `T`'s assignment, the state of its contained value is as defined by the exception safety guarantee of `T`'s copy assignment.
|
||||
* [*Example:]
|
||||
``
|
||||
T v;
|
||||
@@ -727,21 +725,17 @@ __SPACE__
|
||||
|
||||
[: `template<U> optional& optional<T` ['(not a ref)]`>::operator= ( optional<U>&& rhs ) ;`]
|
||||
|
||||
* [*Effect:] Move-assigns another convertible optional to an optional.
|
||||
* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and
|
||||
its value is moved from the value of `rhs`; else
|
||||
`*this` is uninitialized.
|
||||
* [*Throws:] Whatever `T::operator=( U&& )` or `T::T( U&& )` throws.
|
||||
* [*Notes:] If both `*this` and `rhs` are initially initialized, `T`'s
|
||||
[' assignment operator] (from `U&&`) is used. If `*this` is initially initialized
|
||||
but `rhs` is uninitialized, `T`'s ['destructor] is called. If `*this` is
|
||||
initially uninitialized but `rhs` is initialized, `T`'s ['converting constructor]
|
||||
(from `U&&`) is called.
|
||||
* [*Exception Safety:] In the event of an exception, the initialization state
|
||||
of `*this` is unchanged and its value unspecified as far as optional is
|
||||
concerned (it is up to `T`'s `operator=()`). If `*this` is initially
|
||||
uninitialized and `T`'s converting constructor fails, `*this` is left properly
|
||||
uninitialized.
|
||||
* [*Effect:]
|
||||
[table
|
||||
[[][`*this` contains a value][`*this` does not contain a value]]
|
||||
[[`rhs` contains a value][assigns `std::move(*rhs)` to the contained value][initializes the contained value as if direct-initializing an object of type `T` with `std::move(*rhs)`]]
|
||||
[[`rhs` does not contain a value][destroys the contained value by calling `val->T::~T()`][no effect]]
|
||||
]
|
||||
* [*Returns:] `*this`.
|
||||
* [*Postconditions:] `bool(rhs) == bool(*this)`.
|
||||
* [*Exception Safety:] If any exception is thrown, the result of the expression `bool(*this)` remains unchanged.
|
||||
If an exception is thrown during the call to `T`'s constructor, no effect.
|
||||
If an exception is thrown during the call to `T`'s assignment, the state of its contained value is as defined by the exception safety guarantee of `T`'s copy assignment.
|
||||
* [*Example:]
|
||||
``
|
||||
T v;
|
||||
@@ -1256,10 +1250,11 @@ __SPACE__
|
||||
|
||||
* [*Requires:] Lvalues of type `T` shall be swappable and `T` shall be __MOVE_CONSTRUCTIBLE__.
|
||||
* [*Effects:]
|
||||
* If `!*this && !rhs`, no effect, otherwise
|
||||
* if `bool(*this) && !rhs`, initializes the contained value of `rhs` as if direct-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`, `*this` does not contain a value and `rhs` contains a value, otherwise
|
||||
* if `!*this && bool(rhs)`, initializes the contained value of `*this` as if direct-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`, `*this` contains a value and `rhs` does not contain a value, otherwise
|
||||
* (if `bool(*this) && bool(rhs)`) calls `swap(*(*this), *rhs)`.
|
||||
[table
|
||||
[[][`*this` contains a value][`*this` does not contain a value]]
|
||||
[[`rhs` contains a value][calls `swap(*(*this), *rhs)`][initializes the contained value of `*this` as if direct-initializing an object of type `T` with the expression `std::move(*rhs)`, followed by `rhs.val->T::~T()`, `*this` contains a value and `rhs` does not contain a value]]
|
||||
[[`rhs` does not contain a value][initializes the contained value of `rhs` as if direct-initializing an object of type `T` with the expression `std::move(*(*this))`, followed by `val->T::~T()`, `*this` does not contain a value and `rhs` contains a value][no effect]]
|
||||
]
|
||||
* [*Postconditions:] The states of `x` and `y` interchanged.
|
||||
* [*Throws:] If both are initialized, whatever `swap(T&,T&)` throws. If only
|
||||
one is initialized, whatever `T::T ( T&& )` throws.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
* Improved the trick that prevents streaming out `optional` without header `optional_io.hpp` by using safe-bool idiom. This addresses [@https://svn.boost.org/trac/boost/ticket/10825 Trac #10825]
|
||||
* IOStream operators are now mentioned in documentation.
|
||||
* Added a way to manually disable move semantics: just define macro `BOOST_OPTIONAL_CONFIG_NO_RVALUE_REFERENCES`. This can be used to work around [@https://svn.boost.org/trac/boost/ticket/10399 Trac #10399]
|
||||
* It is no longer possible to assign `optional<U>` to `optional<T>` when `U` is not assignable or convertible to `T`.
|
||||
|
||||
|
||||
[heading Boost Release 1.57]
|
||||
|
||||
@@ -808,30 +808,74 @@
|
||||
is <a href="../../../../../utility/CopyConstructible.html" target="_top"><code class="computeroutput"><span class="identifier">CopyConstructible</span></code></a> and <code class="computeroutput"><span class="identifier">CopyAssignable</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<p class="simpara">
|
||||
<span class="bold"><strong>Effects:</strong></span>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
|
||||
<li class="listitem">
|
||||
If <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code> no effect, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code>, destroys the contained value
|
||||
by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>, initializes the contained value
|
||||
as if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code>,
|
||||
otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
(if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>) assigns <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code> to the contained value.
|
||||
</li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains
|
||||
a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
assigns <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code>
|
||||
to the contained value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value as if direct-initializing an
|
||||
object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> does not
|
||||
contain a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
destroys the contained value by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
no effect
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>;
|
||||
</li>
|
||||
@@ -919,30 +963,73 @@
|
||||
and <code class="computeroutput"><span class="identifier">MoveAssignable</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<p class="simpara">
|
||||
<span class="bold"><strong>Effects:</strong></span>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
|
||||
<li class="listitem">
|
||||
If <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code> no effect, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code>, destroys the contained value
|
||||
by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>, initializes the contained value
|
||||
as if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>,
|
||||
otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
(if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>) assigns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code> to the contained value.
|
||||
</li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains
|
||||
a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
assigns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code> to the contained value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value as if direct-initializing an
|
||||
object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> does not
|
||||
contain a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
destroys the contained value by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
no effect
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>;
|
||||
</li>
|
||||
@@ -997,40 +1084,88 @@
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Effect:</strong></span> Assigns another convertible
|
||||
optional to an optional.
|
||||
<p class="simpara">
|
||||
<span class="bold"><strong>Effect:</strong></span>
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains
|
||||
a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
assigns <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code>
|
||||
to the contained value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value as if direct-initializing an
|
||||
object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="special">*</span><span class="identifier">rhs</span></code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> does not
|
||||
contain a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
destroys the contained value by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
no effect
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> If <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
is initialized, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initialized and its value is a <span class="emphasis"><em>copy</em></span> of the value
|
||||
of <code class="computeroutput"><span class="identifier">rhs</span></code> <span class="emphasis"><em>converted</em></span>
|
||||
to type <code class="computeroutput"><span class="identifier">T</span></code>; else <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is uninitialized.
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Throws:</strong></span> Whatever <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">)</span></code> or <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="identifier">T</span><span class="special">(</span> <span class="identifier">U</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">)</span></code> throws.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> If both <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> and rhs are initially initialized,
|
||||
<code class="computeroutput"><span class="identifier">T</span></code>'s <span class="emphasis"><em>assignment
|
||||
operator</em></span> (from <code class="computeroutput"><span class="identifier">U</span></code>)
|
||||
is used. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initially initialized but <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
is uninitialized, <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<span class="emphasis"><em>destructor</em></span> is called. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is initially uninitialized but rhs
|
||||
is initialized, <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<span class="emphasis"><em>converting constructor</em></span> (from <code class="computeroutput"><span class="identifier">U</span></code>)
|
||||
is called.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Exception Safety:</strong></span> In the event of an
|
||||
exception, the initialization state of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is unchanged and its value unspecified
|
||||
as far as optional is concerned (it is up to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<code class="computeroutput"><span class="keyword">operator</span><span class="special">=()</span></code>).
|
||||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initially uninitialized and <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
converting constructor fails, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is left properly uninitialized.
|
||||
<span class="bold"><strong>Exception Safety:</strong></span> If any exception is
|
||||
thrown, the result of the expression <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span></code> remains unchanged. If an exception is
|
||||
thrown during the call to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
constructor, no effect. If an exception is thrown during the call to
|
||||
<code class="computeroutput"><span class="identifier">T</span></code>'s assignment, the state
|
||||
of its contained value is as defined by the exception safety guarantee
|
||||
of <code class="computeroutput"><span class="identifier">T</span></code>'s copy assignment.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
@@ -1053,36 +1188,87 @@
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Effect:</strong></span> Move-assigns another convertible
|
||||
optional to an optional.
|
||||
<p class="simpara">
|
||||
<span class="bold"><strong>Effect:</strong></span>
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains
|
||||
a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
assigns <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code> to the contained value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value as if direct-initializing an
|
||||
object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> does not
|
||||
contain a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
destroys the contained value by calling <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
no effect
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> If <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
is initialized, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initialized and its value is moved from the value of <code class="computeroutput"><span class="identifier">rhs</span></code>; else <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is uninitialized.
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Throws:</strong></span> Whatever <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">U</span><span class="special">&&</span> <span class="special">)</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">T</span><span class="special">::</span><span class="identifier">T</span><span class="special">(</span> <span class="identifier">U</span><span class="special">&&</span>
|
||||
<span class="special">)</span></code> throws.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> If both <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> and <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
are initially initialized, <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<span class="emphasis"><em>assignment operator</em></span> (from <code class="computeroutput"><span class="identifier">U</span><span class="special">&&</span></code>) is used. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initially initialized but <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
is uninitialized, <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<span class="emphasis"><em>destructor</em></span> is called. If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is initially uninitialized but <code class="computeroutput"><span class="identifier">rhs</span></code> is initialized, <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<span class="emphasis"><em>converting constructor</em></span> (from <code class="computeroutput"><span class="identifier">U</span><span class="special">&&</span></code>) is called.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Exception Safety:</strong></span> In the event of an
|
||||
exception, the initialization state of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is unchanged and its value unspecified
|
||||
as far as optional is concerned (it is up to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
<code class="computeroutput"><span class="keyword">operator</span><span class="special">=()</span></code>).
|
||||
If <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
is initially uninitialized and <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
converting constructor fails, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is left properly uninitialized.
|
||||
<span class="bold"><strong>Exception Safety:</strong></span> If any exception is
|
||||
thrown, the result of the expression <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span></code> remains unchanged. If an exception is
|
||||
thrown during the call to <code class="computeroutput"><span class="identifier">T</span></code>'s
|
||||
constructor, no effect. If an exception is thrown during the call to
|
||||
<code class="computeroutput"><span class="identifier">T</span></code>'s assignment, the state
|
||||
of its contained value is as defined by the exception safety guarantee
|
||||
of <code class="computeroutput"><span class="identifier">T</span></code>'s copy assignment.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
@@ -2019,35 +2205,81 @@
|
||||
<span class="bold"><strong>Requires:</strong></span> Lvalues of type <code class="computeroutput"><span class="identifier">T</span></code> shall be swappable and <code class="computeroutput"><span class="identifier">T</span></code> shall be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<p class="simpara">
|
||||
<span class="bold"><strong>Effects:</strong></span>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
|
||||
<li class="listitem">
|
||||
If <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code>, no effect, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="special">!</span><span class="identifier">rhs</span></code>, initializes the contained
|
||||
value of <code class="computeroutput"><span class="identifier">rhs</span></code> as
|
||||
if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with the expression <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">))</span></code>, followed by <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> does not contain a value and
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains a
|
||||
value, otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
if <code class="computeroutput"><span class="special">!*</span><span class="keyword">this</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>, initializes the contained value
|
||||
of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
as if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with the expression <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>, followed by <code class="computeroutput"><span class="identifier">rhs</span><span class="special">.</span><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>, <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> contains a value and <code class="computeroutput"><span class="identifier">rhs</span></code> does not contain a value,
|
||||
otherwise
|
||||
</li>
|
||||
<li class="listitem">
|
||||
(if <code class="computeroutput"><span class="keyword">bool</span><span class="special">(*</span><span class="keyword">this</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="keyword">bool</span><span class="special">(</span><span class="identifier">rhs</span><span class="special">)</span></code>) calls <code class="computeroutput"><span class="identifier">swap</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">),</span> <span class="special">*</span><span class="identifier">rhs</span><span class="special">)</span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> contains
|
||||
a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
calls <code class="computeroutput"><span class="identifier">swap</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">),</span> <span class="special">*</span><span class="identifier">rhs</span><span class="special">)</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value of <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> as if direct-initializing
|
||||
an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with the expression <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*</span><span class="identifier">rhs</span><span class="special">)</span></code>, followed by <code class="computeroutput"><span class="identifier">rhs</span><span class="special">.</span><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>,
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
contains a value and <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
does not contain a value
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rhs</span></code> does not
|
||||
contain a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
initializes the contained value of <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
as if direct-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
with the expression <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(*(*</span><span class="keyword">this</span><span class="special">))</span></code>, followed by <code class="computeroutput"><span class="identifier">val</span><span class="special">-></span><span class="identifier">T</span><span class="special">::~</span><span class="identifier">T</span><span class="special">()</span></code>,
|
||||
<code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
|
||||
does not contain a value and <code class="computeroutput"><span class="identifier">rhs</span></code>
|
||||
contains a value
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
no effect
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> The states of <code class="computeroutput"><span class="identifier">x</span></code> and <code class="computeroutput"><span class="identifier">y</span></code>
|
||||
interchanged.
|
||||
|
||||
@@ -52,6 +52,10 @@
|
||||
This can be used to work around <a href="https://svn.boost.org/trac/boost/ticket/10399" target="_top">Trac
|
||||
#10399</a>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
It is no longer possible to assign <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">></span></code> to <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> when <code class="computeroutput"><span class="identifier">U</span></code>
|
||||
is not assignable or convertible to <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: January 21, 2015 at 13:59:23 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: March 06, 2015 at 18:13:34 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
@@ -188,7 +188,7 @@ struct types_when_is_ref
|
||||
template <class To, class From>
|
||||
void prevent_binding_rvalue_ref_to_optional_lvalue_ref()
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
|
||||
BOOST_STATIC_ASSERT_MSG(
|
||||
!boost::is_lvalue_reference<To>::value || !boost::is_rvalue_reference<From>::value,
|
||||
"binding rvalue references to optional lvalue references is disallowed");
|
||||
@@ -371,13 +371,22 @@ class optional_base : public optional_tag
|
||||
if (is_initialized())
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_RESTORE_ASSIGNMENT_OF_NONCONVERTIBLE_TYPES
|
||||
assign_value(rhs.get(), is_reference_predicate() );
|
||||
#else
|
||||
assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
|
||||
#endif
|
||||
|
||||
else destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
#ifndef BOOST_OPTIONAL_CONFIG_RESTORE_ASSIGNMENT_OF_NONCONVERTIBLE_TYPES
|
||||
construct(rhs.get());
|
||||
#else
|
||||
construct(static_cast<value_type>(rhs.get()));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,5 +56,6 @@ import testing ;
|
||||
[ compile-fail optional_test_fail_explicit_convert_in_value_or.cpp ]
|
||||
[ compile-fail optional_test_fail_explicit_convert_in_value_or_call.cpp ]
|
||||
[ compile-fail optional_test_fail_io_without_io.cpp ]
|
||||
[ compile-fail optional_test_fail_convert_assign_of_enums.cpp ]
|
||||
;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2015, Andrzej Krzemienski.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
#include <iostream>
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
|
||||
enum E1 {e1};
|
||||
enum E2 {e2};
|
||||
|
||||
void test_converitng_assignment_of_different_enums()
|
||||
{
|
||||
boost::optional<E2> o2(e2);
|
||||
boost::optional<E1> o1;
|
||||
o1 = o2;
|
||||
}
|
||||
|
||||
int main() {}
|
||||
Reference in new issue
Block a user