forked from boostorg/optional
Merge branch 'develop'
This commit is contained in:
@ -26,8 +26,9 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
[def __BOOST_TUPLE__ [@../../../tuple/index.html Boost.Tuple]]
|
||||
[def __BOOST_TRIBOOL__ [@../../../../doc/html/tribool.html boost::tribool]]
|
||||
|
||||
[def __OPTIONAL_POINTEE__ [@../../../utility/OptionalPointee.html OptionalPointee]]
|
||||
[def __COPY_CONSTRUCTIBLE__ [@../../../utility/CopyConstructible.html Copy Constructible]]
|
||||
[def __OPTIONAL_POINTEE__ [@../../../utility/OptionalPointee.html `OptionalPointee`]]
|
||||
[def __COPY_CONSTRUCTIBLE__ [@../../../utility/CopyConstructible.html `CopyConstructible`]]
|
||||
[def __MOVE_CONSTRUCTIBLE__ `MoveConstructible`]
|
||||
[def __FUNCTION_EQUAL_POINTEES__ [@../../../utility/OptionalPointee.html#equal `equal_pointees()`]]
|
||||
[def __FUNCTION_LESS_POINTEES__ [@../../../utility/OptionalPointee.html#less `less_pointees()`]]
|
||||
|
||||
|
@ -13,12 +13,12 @@ But this is practically useless. In order for `optional<T>` to be able to do any
|
||||
optional<T> o;
|
||||
o.emplace("T", "ctor", "params");
|
||||
|
||||
If `T` is `MoveConstructible`, `optional<T>` is also `MoveConstructible` and can be easily initialized from an rvalue of type `T` and be passed by value:
|
||||
If `T` is __MOVE_CONSTRUCTIBLE__, `optional<T>` is also __MOVE_CONSTRUCTIBLE__ and can be easily initialized from an rvalue of type `T` and be passed by value:
|
||||
|
||||
optional<T> o = make_T();
|
||||
optional<T> p = optional<T>();
|
||||
|
||||
If `T` is `CopyConstructible`, `optional<T>` is also `CopyConstructible` and can be easily initialized from an lvalue of type `T`:
|
||||
If `T` is __COPY_CONSTRUCTIBLE__, `optional<T>` is also __COPY_CONSTRUCTIBLE__ and can be easily initialized from an lvalue of type `T`:
|
||||
|
||||
T v = make_T();
|
||||
optional<T> o = v;
|
||||
@ -29,9 +29,9 @@ If `T` is not `MoveAssignable`, it is still possible to reset the value of `opti
|
||||
optional<const T> o = make_T();
|
||||
o.emplace(make_another_T());
|
||||
|
||||
If `T` is `Moveable` (both `MoveConstructible` and `MoveAssignable`) then `optional<T>` is also `Moveable` and additionally can be constructed and assigned from an rvalue of type `T`.
|
||||
If `T` is `Moveable` (both __MOVE_CONSTRUCTIBLE__ and `MoveAssignable`) then `optional<T>` is also `Moveable` and additionally can be constructed and assigned from an rvalue of type `T`.
|
||||
|
||||
Similarly, if `T` is `Copyable` (both `CopyConstructible` and `CopyAssignable`) then `optional<T>` is also `Copyable` and additionally can be constructed and assigned from an lvalue of type `T`.
|
||||
Similarly, if `T` is `Copyable` (both __COPY_CONSTRUCTIBLE__ and `CopyAssignable`) then `optional<T>` is also `Copyable` and additionally can be constructed and assigned from an lvalue of type `T`.
|
||||
|
||||
`T` ['is not] required to be __SGI_DEFAULT_CONSTRUCTIBLE__.
|
||||
|
||||
|
@ -80,12 +80,12 @@
|
||||
T&& value() && ; ``[link reference_optional_value __GO_TO__]``
|
||||
|
||||
template<class U> T value_or( U && v ) const& ; ``[link reference_optional_value_or __GO_TO__]``
|
||||
template<class U> T value_or( U && v ) && ; ``[link reference_optional_value_or __GO_TO__]``
|
||||
template<class U> T value_or( U && v ) && ; ``[link reference_optional_value_or_move __GO_TO__]``
|
||||
|
||||
T const* get_ptr() const ; ``[link reference_optional_get_ptr __GO_TO__]``
|
||||
T* get_ptr() ; ``[link reference_optional_get_ptr __GO_TO__]``
|
||||
|
||||
explicit operator bool() const ; ``[link reference_optional_operator_bool __GO_TO__]``
|
||||
explicit operator bool() const noexcept ; ``[link reference_optional_operator_bool __GO_TO__]``
|
||||
|
||||
bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]``
|
||||
|
||||
@ -761,7 +761,7 @@ __SPACE__
|
||||
of type `T` with `std::forward<Args>(args)...`.
|
||||
* [*Postconditions: ] `*this` is [_initialized].
|
||||
* [*Throws:] Whatever the selected `T`'s constructor throws.
|
||||
* [*Notes:] `T` need not be `MoveConstructible` or `MoveAssignable`. On compilers that do not support variadic templates, the signature falls back to single-argument: `template<class Arg> void emplace(Arg&& arg)`. On compilers that do not support rvalue references, the signature falls back to two overloads: taking `const` and non-`const` lvalue reference.
|
||||
* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. On compilers that do not support variadic templates, the signature falls back to single-argument: `template<class Arg> void emplace(Arg&& arg)`. On compilers that do not support rvalue references, the signature falls back to two overloads: taking `const` and non-`const` lvalue reference.
|
||||
* [*Exception Safety:] If an exception is thrown during the initialization of `T`, `*this` is ['uninitialized].
|
||||
* [*Example:]
|
||||
``
|
||||
@ -906,12 +906,22 @@ __SPACE__
|
||||
[#reference_optional_value_or]
|
||||
|
||||
[: `template<class U> T optional<T>::value_or(U && v) const& ;`]
|
||||
|
||||
* [*Requires:] `T` is __COPY_CONSTRUCTIBLE__ and `U &&` is convertible to `T`.
|
||||
* [*Returns:] `bool(*this) ? **this : static_cast<T>(forward<U>(v))`.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes:] On compilers that do not support ref-qualifiers on member functions this overload is replaced with the `const`-qualified member function. On compilers without rvalue reference support the type of `v` becomes `U const&`.
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_value_or_move]
|
||||
|
||||
[: `template<class U> T optional<T>::value_or(U && v) && ;`]
|
||||
|
||||
* [*Requires:] `T` is CopyConstructible.
|
||||
* [*Returns:] First overload: `bool(*this) ? **this : static_cast<T>(forward<U>(v))`. second overload: `bool(*this) ? std::move(**this) : static_cast<T>(forward<U>(v))`.
|
||||
* [*Requires:] `T` is __MOVE_CONSTRUCTIBLE__ and `U &&` is convertible to `T`.
|
||||
* [*Returns:] `bool(*this) ? std::move(**this) : static_cast<T>(forward<U>(v))`.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes:] On compilers that do not support ref-qualifiers on member functions these three overloads are replaced with the classical two: a `const` and non-`const` member functions. On compilers without rvalue reference support the type of `v` becomes `U const&`.
|
||||
* [*Notes:] On compilers that do not support ref-qualifiers on member functions this overload is replaced with the classical non-`const`-qualified member function. On compilers without rvalue reference support the type of `v` becomes `U const&`.
|
||||
|
||||
__SPACE__
|
||||
|
||||
@ -989,10 +999,9 @@ __SPACE__
|
||||
|
||||
[#reference_optional_operator_bool]
|
||||
|
||||
[: `explicit optional<T>::operator bool() const ;`]
|
||||
[: `explicit optional<T>::operator bool() const noexcept ;`]
|
||||
|
||||
* [*Returns:] `get_ptr() != 0`.
|
||||
* [*Throws:] Nothing.
|
||||
* [*Notes:] On compilers that do not support explicit conversion operators this falls back to safe-bool idiom.
|
||||
* [*Example:]
|
||||
``
|
||||
|
@ -1400,19 +1400,14 @@
|
||||
<span class="keyword">const</span><span class="special">&</span>
|
||||
<span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">value_or</span><span class="special">(</span><span class="identifier">U</span> <span class="special">&&</span>
|
||||
<span class="identifier">v</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
is CopyConstructible.
|
||||
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">U</span> <span class="special">&&</span></code>
|
||||
is convertible to <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> First overload: <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="keyword">this</span>
|
||||
<span class="special">:</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">U</span><span class="special">>(</span><span class="identifier">v</span><span class="special">))</span></code>. second overload: <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="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> <span class="special">:</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">U</span><span class="special">>(</span><span class="identifier">v</span><span class="special">))</span></code>.
|
||||
<span class="bold"><strong>Returns:</strong></span> <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="keyword">this</span> <span class="special">:</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">U</span><span class="special">>(</span><span class="identifier">v</span><span class="special">))</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Throws:</strong></span> Any exception thrown by the
|
||||
@ -1420,13 +1415,42 @@
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> On compilers that do not support
|
||||
ref-qualifiers on member functions these three overloads are replaced
|
||||
with the classical two: a <code class="computeroutput"><span class="keyword">const</span></code>
|
||||
and non-<code class="computeroutput"><span class="keyword">const</span></code> member functions.
|
||||
ref-qualifiers on member functions this overload is replaced with the
|
||||
<code class="computeroutput"><span class="keyword">const</span></code>-qualified member function.
|
||||
On compilers without rvalue reference support the type of <code class="computeroutput"><span class="identifier">v</span></code> becomes <code class="computeroutput"><span class="identifier">U</span>
|
||||
<span class="keyword">const</span><span class="special">&</span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="reference_optional_value_or_move"></a><div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">value_or</span><span class="special">(</span><span class="identifier">U</span> <span class="special">&&</span>
|
||||
<span class="identifier">v</span><span class="special">)</span>
|
||||
<span class="special">&&</span> <span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
is <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">U</span> <span class="special">&&</span></code>
|
||||
is convertible to <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <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="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> <span class="special">:</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">T</span><span class="special">>(</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">U</span><span class="special">>(</span><span class="identifier">v</span><span class="special">))</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Throws:</strong></span> Any exception thrown by the
|
||||
selected constructor of <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> On compilers that do not support
|
||||
ref-qualifiers on member functions this overload is replaced with the
|
||||
classical non-<code class="computeroutput"><span class="keyword">const</span></code>-qualified
|
||||
member function. On compilers without rvalue reference support the type
|
||||
of <code class="computeroutput"><span class="identifier">v</span></code> becomes <code class="computeroutput"><span class="identifier">U</span> <span class="keyword">const</span><span class="special">&</span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
@ -1572,15 +1596,13 @@
|
||||
<a name="reference_optional_operator_bool"></a><div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<code class="computeroutput"><span class="keyword">explicit</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="keyword">operator</span>
|
||||
<span class="keyword">bool</span><span class="special">()</span>
|
||||
<span class="keyword">const</span> <span class="special">;</span></code>
|
||||
<span class="keyword">const</span> <span class="keyword">noexcept</span>
|
||||
<span class="special">;</span></code>
|
||||
</p></blockquote></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Returns:</strong></span> <code class="computeroutput"><span class="identifier">get_ptr</span><span class="special">()</span> <span class="special">!=</span> <span class="number">0</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Throws:</strong></span> Nothing.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Notes:</strong></span> On compilers that do not support
|
||||
explicit conversion operators this falls back to safe-bool idiom.
|
||||
|
@ -98,10 +98,11 @@
|
||||
</p>
|
||||
<p>
|
||||
Such a <span class="emphasis"><em>de facto</em></span> idiom for referring to optional objects
|
||||
can be formalized in the form of a concept: the <a href="../../../../../../utility/OptionalPointee.html" target="_top">OptionalPointee</a>
|
||||
concept. This concept captures the syntactic usage of operators <code class="computeroutput"><span class="special">*</span></code>, <code class="computeroutput"><span class="special">-></span></code>
|
||||
and contextual conversion to <code class="computeroutput"><span class="keyword">bool</span></code>
|
||||
to convey the notion of optionality.
|
||||
can be formalized in the form of a concept: the <a href="../../../../../../utility/OptionalPointee.html" target="_top"><code class="computeroutput"><span class="identifier">OptionalPointee</span></code></a> concept. This
|
||||
concept captures the syntactic usage of operators <code class="computeroutput"><span class="special">*</span></code>,
|
||||
<code class="computeroutput"><span class="special">-></span></code> and contextual conversion
|
||||
to <code class="computeroutput"><span class="keyword">bool</span></code> to convey the notion
|
||||
of optionality.
|
||||
</p>
|
||||
<p>
|
||||
However, pointers are good to <span class="underline">refer</span>
|
||||
@ -127,7 +128,7 @@
|
||||
this semantics, so are inappropriate for the initialization and transport
|
||||
of optional values, yet are quite convenient for handling the access to
|
||||
the possible undefined value because of the idiomatic aid present in the
|
||||
<a href="../../../../../../utility/OptionalPointee.html" target="_top">OptionalPointee</a>
|
||||
<a href="../../../../../../utility/OptionalPointee.html" target="_top"><code class="computeroutput"><span class="identifier">OptionalPointee</span></code></a>
|
||||
concept incarnated by pointers.
|
||||
</p>
|
||||
<h6>
|
||||
|
@ -31,9 +31,9 @@
|
||||
One of the typical problems with wrappers and containers is that their interfaces
|
||||
usually provide an operation to initialize or assign the contained object
|
||||
as a copy of some other object. This not only requires the underlying type
|
||||
to be <a href="../../../../../utility/CopyConstructible.html" target="_top">Copy Constructible</a>,
|
||||
but also requires the existence of a fully constructed object, often temporary,
|
||||
just to follow the copy from:
|
||||
to be <a href="../../../../../utility/CopyConstructible.html" target="_top"><code class="computeroutput"><span class="identifier">CopyConstructible</span></code></a>, but also requires
|
||||
the existence of a fully constructed object, often temporary, just to follow
|
||||
the copy from:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">X</span>
|
||||
<span class="special">{</span>
|
||||
|
@ -60,10 +60,9 @@
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">>();</span>
|
||||
</pre>
|
||||
<p>
|
||||
If <code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">CopyConstructible</span></code>,
|
||||
<code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is
|
||||
also <code class="computeroutput"><span class="identifier">CopyConstructible</span></code> and
|
||||
can be easily initialized from an lvalue of type <code class="computeroutput"><span class="identifier">T</span></code>:
|
||||
If <code class="computeroutput"><span class="identifier">T</span></code> is <a href="../../../../../utility/CopyConstructible.html" target="_top"><code class="computeroutput"><span class="identifier">CopyConstructible</span></code></a>, <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is
|
||||
also <a href="../../../../../utility/CopyConstructible.html" target="_top"><code class="computeroutput"><span class="identifier">CopyConstructible</span></code></a>
|
||||
and can be easily initialized from an lvalue of type <code class="computeroutput"><span class="identifier">T</span></code>:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">T</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">make_T</span><span class="special">();</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">o</span> <span class="special">=</span> <span class="identifier">v</span><span class="special">;</span>
|
||||
@ -85,10 +84,8 @@
|
||||
can be constructed and assigned from an rvalue of type <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Similarly, if <code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">Copyable</span></code> (both <code class="computeroutput"><span class="identifier">CopyConstructible</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">CopyAssignable</span></code>) then
|
||||
<code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> is
|
||||
also <code class="computeroutput"><span class="identifier">Copyable</span></code> and additionally
|
||||
Similarly, if <code class="computeroutput"><span class="identifier">T</span></code> is <code class="computeroutput"><span class="identifier">Copyable</span></code> (both <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>) then <code class="computeroutput"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>
|
||||
is also <code class="computeroutput"><span class="identifier">Copyable</span></code> and additionally
|
||||
can be constructed and assigned from an lvalue of type <code class="computeroutput"><span class="identifier">T</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
|
@ -133,7 +133,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: June 08, 2014 at 18:14:37 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: June 16, 2014 at 12:04:51 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -104,12 +104,12 @@
|
||||
<span class="identifier">T</span><span class="special">&&</span> <span class="identifier">value</span><span class="special">()</span> <span class="special">&&</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_value"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">value_or</span><span class="special">(</span> <span class="identifier">U</span> <span class="special">&&</span> <span class="identifier">v</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">&</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_value_or"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">value_or</span><span class="special">(</span> <span class="identifier">U</span> <span class="special">&&</span> <span class="identifier">v</span> <span class="special">)</span> <span class="special">&&</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_value_or"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span> <span class="identifier">T</span> <span class="identifier">value_or</span><span class="special">(</span> <span class="identifier">U</span> <span class="special">&&</span> <span class="identifier">v</span> <span class="special">)</span> <span class="special">&&</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_value_or_move"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="identifier">T</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">get_ptr</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_get_ptr"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="identifier">T</span><span class="special">*</span> <span class="identifier">get_ptr</span><span class="special">()</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_get_ptr"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="keyword">explicit</span> <span class="keyword">operator</span> <span class="keyword">bool</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_operator_bool"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="keyword">explicit</span> <span class="keyword">operator</span> <span class="keyword">bool</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_operator_bool"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span> <span class="special">;</span> <a class="link" href="../boost_optional/reference/detailed_semantics.html#reference_optional_operator_not"><span class="inlinemediaobject"><img src="../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/core/explicit_operator_bool.hpp>
|
||||
#include <boost/optional/bad_optional_access.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
@ -34,6 +35,7 @@
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/decay.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/is_lvalue_reference.hpp>
|
||||
#include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
||||
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
|
||||
@ -49,7 +51,7 @@
|
||||
#include <boost/utility/addressof.hpp>
|
||||
#include <boost/utility/compare_pointees.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/utility/explicit_operator_bool.hpp>
|
||||
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
#include <boost/utility/swap.hpp>
|
||||
|
||||
@ -1059,23 +1061,36 @@ class optional : public optional_detail::optional_base<T>
|
||||
#ifndef BOOST_NO_CXX11_REF_QUALIFIERS
|
||||
template <class U>
|
||||
value_type value_or ( U&& v ) const&
|
||||
{ return this->is_initialized() ? get() : static_cast<value_type>(boost::forward<U>(v)); }
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_convertible<U&&, value_type>::value));
|
||||
return this->is_initialized() ? get() : static_cast<value_type>(boost::forward<U>(v));
|
||||
}
|
||||
|
||||
template <class U>
|
||||
value_type value_or ( U&& v ) &&
|
||||
{ return this->is_initialized() ? boost::move(get()) : static_cast<value_type>(boost::forward<U>(v)); }
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_convertible<U&&, value_type>::value));
|
||||
return this->is_initialized() ? boost::move(get()) : static_cast<value_type>(boost::forward<U>(v));
|
||||
}
|
||||
#elif !defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template <class U>
|
||||
value_type value_or ( U&& v ) const
|
||||
{ return this->is_initialized() ? get() : static_cast<value_type>(boost::forward<U>(v)); }
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_convertible<U&&, value_type>::value));
|
||||
return this->is_initialized() ? get() : static_cast<value_type>(boost::forward<U>(v));
|
||||
}
|
||||
#else
|
||||
template <class U>
|
||||
value_type value_or ( U const& v ) const { return this->is_initialized() ? get() : static_cast<value_type>(v); }
|
||||
value_type value_or ( U const& v ) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_convertible<U const&, value_type>::value));
|
||||
return this->is_initialized() ? get() : static_cast<value_type>(v);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool operator!() const BOOST_NOEXCEPT { return !this->is_initialized() ; }
|
||||
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||
} ;
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
@ -41,5 +41,6 @@ import testing ;
|
||||
[ compile-fail optional_test_ref_fail_init_from_Urefref.cpp ]
|
||||
[ compile-fail optional_test_ref_fail_assign_from_Trefref.cpp ]
|
||||
[ compile-fail optional_test_ref_fail_assign_from_Urefref.cpp ]
|
||||
[ compile-fail optional_test_fail_explicit_convert_in_value_or.cpp ]
|
||||
;
|
||||
}
|
||||
|
32
test/optional_test_fail_explicit_convert_in_value_or.cpp
Normal file
32
test/optional_test_fail_explicit_convert_in_value_or.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2014, 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 "boost/optional.hpp"
|
||||
|
||||
//
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
//
|
||||
|
||||
struct U
|
||||
{};
|
||||
|
||||
struct T
|
||||
{
|
||||
explicit T(U const&) {}
|
||||
};
|
||||
|
||||
|
||||
void test_implicit_conversion_to_bool()
|
||||
{
|
||||
boost::optional<T> opt;
|
||||
opt.value_or(U());
|
||||
}
|
||||
|
Reference in New Issue
Block a user