mirror of
https://github.com/boostorg/optional.git
synced 2025-07-13 12:26:36 +02:00
Compare commits
36 Commits
boost-1.62
...
boost-1.65
Author | SHA1 | Date | |
---|---|---|---|
975a6aa92d | |||
cb7641dc34 | |||
2124f71299 | |||
1618d5f3bb | |||
17826eae3b | |||
d73b5110dd | |||
b4907c2a51 | |||
fafb3abb64 | |||
7ea2ca6c40 | |||
50fb8738f8 | |||
8d69e99e78 | |||
9bc1cc585c | |||
4e08f0dd41 | |||
4a9d53539c | |||
9af24038bc | |||
92d40c7108 | |||
eb9ea1f72d | |||
a710a23102 | |||
e7b310bcc2 | |||
d556ccedb2 | |||
63454c11aa | |||
54e0bc6f04 | |||
9f8823aebf | |||
62acbe1690 | |||
3e0051be7e | |||
72b3b23475 | |||
b8da1932f3 | |||
1c31338da3 | |||
99efe72052 | |||
f9324a8790 | |||
b99c1fdcc2 | |||
088e2e3051 | |||
5d5d1f46ba | |||
08076e3964 | |||
844ca6a0d5 | |||
0755ab7b4e |
@ -102,7 +102,7 @@ Sometimes on GCC compilers below version 5.1 you may get an -Wmaybe-uninitialize
|
||||
|
||||
This is a bug in the compiler. As a workaround (provided in [@http://stackoverflow.com/questions/21755206/how-to-get-around-gcc-void-b-4-may-be-used-uninitialized-in-this-funct this Stack Overflow question]) use the following way of initializing an optional containing no value:
|
||||
|
||||
boost::optional<int> b = std::make_optional(false, int());
|
||||
boost::optional<int> b = boost::make_optional(false, int());
|
||||
|
||||
This is obviously redundant, but makes the warning disappear.
|
||||
|
||||
|
@ -15,6 +15,12 @@
|
||||
|
||||
namespace boost {
|
||||
|
||||
class in_place_init_t { /* see below */ } ; ``[link reference_in_place_init __GO_TO__]``
|
||||
const in_place_init_t in_place_init ( /* see below */ ) ;
|
||||
|
||||
class in_place_init_if_t { /*see below*/ } ; ``[link reference_in_place_init_if __GO_TO__]``
|
||||
const in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
|
||||
|
||||
template <class T>
|
||||
class optional ; ``[link reference_operator_template __GO_TO__]``
|
||||
|
||||
@ -67,6 +73,26 @@
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:header_optional_in_place_init Initialization tags]
|
||||
|
||||
[#reference_in_place_init]
|
||||
[#reference_in_place_init_if]
|
||||
|
||||
namespace boost {
|
||||
|
||||
class in_place_init_t { /* see below */ } ;
|
||||
const in_place_init_t in_place_init ( /* see below */ ) ;
|
||||
|
||||
class in_place_init_if_t { /*see below*/ } ;
|
||||
const in_place_init_if_t in_place_init_if ( /*see below*/ ) ;
|
||||
|
||||
}
|
||||
|
||||
Classes `in_place_init_t` and `in_place_init_if_t` are empty clsses. Their purpose is to control overload resolution in the initialization of optional objects.
|
||||
They are empty, trivially copyable classes with disabled default constructor.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:header_optional_optional_values Optional Values]
|
||||
|
||||
[#reference_operator_template]
|
||||
@ -91,7 +117,6 @@
|
||||
|
||||
optional ( T&& v ) ; ``[link reference_optional_constructor_move_value __GO_TO__]``
|
||||
|
||||
// [new in 1.34]
|
||||
optional ( bool condition, T const& v ) ; ``[link reference_optional_constructor_bool_value __GO_TO__]``
|
||||
|
||||
optional ( optional const& rhs ) ; ``[link reference_optional_constructor_optional __GO_TO__]``
|
||||
@ -101,6 +126,10 @@
|
||||
template<class U> explicit optional ( optional<U> const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]``
|
||||
|
||||
template<class U> explicit optional ( optional<U>&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]``
|
||||
|
||||
template<class... Args> explicit optional ( in_place_init_t, Args&&... args ) ; ``[link reference_optional_in_place_init __GO_TO__]``
|
||||
|
||||
template<class... Args> explicit optional ( in_place_init_if_t, bool condition, Args&&... args ) ; ``[link reference_optional_in_place_init_if __GO_TO__]``
|
||||
|
||||
template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
|
||||
|
||||
|
@ -224,6 +224,53 @@ assert( *y == 123 ) ;
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_in_place_init]
|
||||
|
||||
[: `template<class... Args> explicit optional<T>::optional( in_place_init_t, Args&&... ars );`]
|
||||
|
||||
* [*Requires:] `is_constructible_v<T, Args&&...>` is `true`.
|
||||
* [*Effect:] Initializes the contained value as if direct-non-list-initializing an object of type `T` with the
|
||||
arguments `std::forward<Args>(args)...`.
|
||||
* [*Postconditions:] `*this` is initialized.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not suppor variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
|
||||
* [*Example:]
|
||||
``
|
||||
// creates an std::mutex using its default constructor
|
||||
optional<std::mutex> om {in_place_init};
|
||||
assert (om);
|
||||
|
||||
// creates a unique_lock by calling unique_lock(*om, std::defer_lock)
|
||||
optional<std::unique_lock<std::mutex>> ol {in_place_init, *om, std::defer_lock};
|
||||
assert (ol);
|
||||
assert (!ol->owns_lock());
|
||||
``
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_in_place_init_if]
|
||||
|
||||
[: `template<class... Args> explicit optional<T>::optional( in_place_init_if_t, bool condition, Args&&... ars );`]
|
||||
|
||||
* [*Requires:] `is_constructible_v<T, Args&&...>` is `true`.
|
||||
* [*Effect:] If `condition` is `true`, initializes the contained value as if direct-non-list-initializing an object of type `T` with the arguments `std::forward<Args>(args)...`.
|
||||
* [*Postconditions:] `bool(*this) == condition`.
|
||||
* [*Throws:] Any exception thrown by the selected constructor of `T`.
|
||||
* [*Notes: ] `T` need not be __MOVE_CONSTRUCTIBLE__. On compilers that do not suppor variadic templates or rvalue references, this constuctor is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
|
||||
* [*Example:]
|
||||
``
|
||||
optional<std::vector<std::string>> ov1 {in_place_init_if, false, 3, "A"};
|
||||
assert (!ov1);
|
||||
|
||||
optional<std::vector<std::string>> ov2 {in_place_init_if, true, 3, "A"};
|
||||
assert (ov2);
|
||||
assert (ov2->size() == 3);
|
||||
``
|
||||
|
||||
__SPACE__
|
||||
|
||||
[#reference_optional_constructor_factory]
|
||||
|
||||
[: `template<InPlaceFactory> explicit optional<T>::optional( InPlaceFactory const& f );`]
|
||||
@ -455,9 +502,7 @@ __SPACE__
|
||||
* [*Postconditions: ] `*this` is [_initialized].
|
||||
* [*Throws:] Whatever the selected `T`'s constructor throws.
|
||||
* [*Exception Safety:] If an exception is thrown during the initialization of `T`, `*this` is ['uninitialized].
|
||||
* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`.
|
||||
On compilers that do not support variadic templates, the signature falls back to two overloads:`template<class Arg> void emplace(Arg&& arg)` and `void emplace()`.
|
||||
On compilers that do not support rvalue references, the signature falls back to three overloads: taking `const` and non-`const` lvalue reference, and third with empty function argument list.
|
||||
* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. On compilers that do not suppor variadic templates or rvalue references, this function is available in limited functionality. For details [link optional_emplace_workaround see here].
|
||||
* [*Example:]
|
||||
``
|
||||
T v;
|
||||
|
@ -27,6 +27,41 @@ The implementation uses the following other Boost modules:
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Emplace operations in older compilers][#optional_emplace_workaround]
|
||||
|
||||
Certain constructors and functions in the interface of `optional` perform a 'perfect forwarding' of arguments:
|
||||
|
||||
template<class... Args> optional(in_place_init_t, Args&&... args);
|
||||
template<class... Args> optional(in_place_init_if_t, bool condition, Args&&... args);
|
||||
template<class... Args> void emplace(Args&&... args);
|
||||
|
||||
On compilers that do not support variadic templates, each of these functions is substituted with two overloads, one forwarding a single argument, the other forwarding zero arguments. This forms the following set:
|
||||
|
||||
template<class Arg> optional(in_place_init_t, Arg&& arg);
|
||||
optional(in_place_init_t);
|
||||
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, Arg&& arg);
|
||||
optional(in_place_init_if_t, bool condition);
|
||||
|
||||
template<class Arg> void emplace(Arg&& arg);
|
||||
void emplace();
|
||||
|
||||
On compilers that do not support rvalue references, each of these functions is substituted with three overloadss: taking `const` and non-`const` lvalue reference, and third forwarding zero arguments. This forms the following set:
|
||||
|
||||
template<class Arg> optional(in_place_init_t, const Arg& arg);
|
||||
template<class Arg> optional(in_place_init_t, Arg& arg);
|
||||
optional(in_place_init_t);
|
||||
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, const Arg& arg);
|
||||
template<class Arg> optional(in_place_init_if_t, bool condition, Arg& arg);
|
||||
optional(in_place_init_if_t, bool condition);
|
||||
|
||||
template<class Arg> void emplace(const Arg& arg);
|
||||
template<class Arg> void emplace(Arg& arg);
|
||||
void emplace();
|
||||
|
||||
This workaround addressess about 40% of all use cases. If this is insufficient, you need to resort to using [link boost_optional.tutorial.in_place_factories In-Place Factories].
|
||||
[endsect]
|
||||
|
||||
[section Optional Reference Binding][#optional_reference_binding]
|
||||
|
||||
|
@ -11,6 +11,12 @@
|
||||
|
||||
[section:relnotes Release Notes]
|
||||
|
||||
[heading Boost Release 1.63]
|
||||
* Added two new in-place constructors. They work similarly to `emplace()` functions: they initialize the contained value by perfect-forwarding the obtained arguments. One constructor always initializes the contained value, the other based on a boolean condition.
|
||||
* Syntax `o = {}` now correctly un-initializes optional, just like in `std::optional`.
|
||||
* Fixed [@https://svn.boost.org/trac/boost/ticket/12203 Trac #12203].
|
||||
* Fixed [@https://svn.boost.org/trac/boost/ticket/12563 Trac #12563].
|
||||
|
||||
|
||||
[heading Boost Release 1.62]
|
||||
|
||||
|
@ -46,4 +46,8 @@ boostbook standalone
|
||||
<format>docbook:<auto-index-internal>on
|
||||
;
|
||||
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease : standalone ;
|
||||
explicit boostrelease ;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<link rel="home" href="../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../index.html" title="Boost.Optional">
|
||||
<link rel="prev" href="reference/header__boost_optional_hpp_.html" title="Header <boost/optional.hpp>">
|
||||
<link rel="next" href="dependencies_and_portability/optional_reference_binding.html" title="Optional Reference Binding">
|
||||
<link rel="next" href="dependencies_and_portability/emplace_operations_in_older_compilers.html" title="Emplace operations in older compilers">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@ -20,7 +20,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="reference/header__boost_optional_hpp_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="dependencies_and_portability/optional_reference_binding.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="reference/header__boost_optional_hpp_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="dependencies_and_portability/emplace_operations_in_older_compilers.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
@ -29,6 +29,8 @@
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="dependencies_and_portability.html#boost_optional.dependencies_and_portability.dependencies">Dependencies</a></span></dt>
|
||||
<dt><span class="section"><a href="dependencies_and_portability/emplace_operations_in_older_compilers.html">Emplace
|
||||
operations in older compilers</a></span></dt>
|
||||
<dt><span class="section"><a href="dependencies_and_portability/optional_reference_binding.html">Optional
|
||||
Reference Binding</a></span></dt>
|
||||
</dl></div>
|
||||
@ -83,7 +85,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="reference/header__boost_optional_hpp_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="dependencies_and_portability/optional_reference_binding.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="reference/header__boost_optional_hpp_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="dependencies_and_portability/emplace_operations_in_older_compilers.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -0,0 +1,90 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Emplace operations in older compilers</title>
|
||||
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
<link rel="prev" href="../dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
<link rel="next" href="optional_reference_binding.html" title="Optional Reference Binding">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="optional_reference_binding.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_optional.dependencies_and_portability.emplace_operations_in_older_compilers"></a><a class="link" href="emplace_operations_in_older_compilers.html" title="Emplace operations in older compilers">Emplace
|
||||
operations in older compilers</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<a name="optional_emplace_workaround"></a>Certain constructors and functions
|
||||
in the interface of <code class="computeroutput"><span class="identifier">optional</span></code>
|
||||
perform a 'perfect forwarding' of arguments:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span><span class="special">);</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span><span class="special">);</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
On compilers that do not support variadic templates, each of these functions
|
||||
is substituted with two overloads, one forwarding a single argument, the
|
||||
other forwarding zero arguments. This forms the following set:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Arg</span><span class="special">&&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">();</span>
|
||||
</pre>
|
||||
<p>
|
||||
On compilers that do not support rvalue references, each of these functions
|
||||
is substituted with three overloadss: taking <code class="computeroutput"><span class="keyword">const</span></code>
|
||||
and non-<code class="computeroutput"><span class="keyword">const</span></code> lvalue reference,
|
||||
and third forwarding zero arguments. This forms the following set:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_t</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="identifier">optional</span><span class="special">(</span><span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Arg</span><span class="special">></span> <span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Arg</span><span class="special">&</span> <span class="identifier">arg</span><span class="special">);</span>
|
||||
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">();</span>
|
||||
</pre>
|
||||
<p>
|
||||
This workaround addressess about 40% of all use cases. If this is insufficient,
|
||||
you need to resort to using <a class="link" href="../tutorial/in_place_factories.html" title="In-Place Factories">In-Place
|
||||
Factories</a>.
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2003-2007 Fernando Luis Cacciola Carballal<br>Copyright © 2014-2016 Andrzej Krzemieński<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="optional_reference_binding.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -6,7 +6,7 @@
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
<link rel="prev" href="../dependencies_and_portability.html" title="Dependencies and Portability">
|
||||
<link rel="prev" href="emplace_operations_in_older_compilers.html" title="Emplace operations in older compilers">
|
||||
<link rel="next" href="../relnotes.html" title="Release Notes">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@ -20,7 +20,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../relnotes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="emplace_operations_in_older_compilers.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../relnotes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
@ -101,7 +101,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../relnotes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="emplace_operations_in_older_compilers.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dependencies_and_portability.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../relnotes.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -403,6 +403,94 @@
|
||||
</pre>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="reference_optional_in_place_init"></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="special">...</span> <span class="identifier">Args</span><span class="special">></span>
|
||||
<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="identifier">optional</span><span class="special">(</span> <span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">ars</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">is_constructible_v</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...></span></code> is <code class="computeroutput"><span class="keyword">true</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Effect:</strong></span> Initializes the contained
|
||||
value as if direct-non-list-initializing an object of type <code class="computeroutput"><span class="identifier">T</span></code> with the arguments <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">Args</span><span class="special">>(</span><span class="identifier">args</span><span class="special">)...</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</strong></span> <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> is initialized.
|
||||
</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> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
this constuctor is available in limited functionality. For details
|
||||
<a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
<pre class="programlisting"><span class="comment">// creates an std::mutex using its default constructor</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">mutex</span><span class="special">></span> <span class="identifier">om</span> <span class="special">{</span><span class="identifier">in_place_init</span><span class="special">};</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">om</span><span class="special">);</span>
|
||||
|
||||
<span class="comment">// creates a unique_lock by calling unique_lock(*om, std::defer_lock)</span>
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">unique_lock</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">mutex</span><span class="special">>></span> <span class="identifier">ol</span> <span class="special">{</span><span class="identifier">in_place_init</span><span class="special">,</span> <span class="special">*</span><span class="identifier">om</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">defer_lock</span><span class="special">};</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">ol</span><span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(!</span><span class="identifier">ol</span><span class="special">-></span><span class="identifier">owns_lock</span><span class="special">());</span>
|
||||
</pre>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
<a name="reference_optional_in_place_init_if"></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="special">...</span> <span class="identifier">Args</span><span class="special">></span>
|
||||
<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="identifier">optional</span><span class="special">(</span> <span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span>
|
||||
<span class="identifier">Args</span><span class="special">&&...</span>
|
||||
<span class="identifier">ars</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">is_constructible_v</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...></span></code> is <code class="computeroutput"><span class="keyword">true</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Effect:</strong></span> If <code class="computeroutput"><span class="identifier">condition</span></code>
|
||||
is <code class="computeroutput"><span class="keyword">true</span></code>, initializes the
|
||||
contained value as if direct-non-list-initializing an object of type
|
||||
<code class="computeroutput"><span class="identifier">T</span></code> with the arguments
|
||||
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special"><</span><span class="identifier">Args</span><span class="special">>(</span><span class="identifier">args</span><span class="special">)...</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Postconditions:</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">condition</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> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
this constuctor is available in limited functionality. For details
|
||||
<a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
<pre class="programlisting"><span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">>></span> <span class="identifier">ov1</span> <span class="special">{</span><span class="identifier">in_place_init_if</span><span class="special">,</span> <span class="keyword">false</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="string">"A"</span><span class="special">};</span>
|
||||
<span class="identifier">assert</span> <span class="special">(!</span><span class="identifier">ov1</span><span class="special">);</span>
|
||||
|
||||
<span class="identifier">optional</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">>></span> <span class="identifier">ov2</span> <span class="special">{</span><span class="identifier">in_place_init_if</span><span class="special">,</span> <span class="keyword">true</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="string">"A"</span><span class="special">};</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">ov2</span><span class="special">);</span>
|
||||
<span class="identifier">assert</span> <span class="special">(</span><span class="identifier">ov2</span><span class="special">-></span><span class="identifier">size</span><span class="special">()</span> <span class="special">==</span> <span class="number">3</span><span class="special">);</span>
|
||||
</pre>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../images/space.png" alt="space"></span>
|
||||
</p>
|
||||
@ -1037,15 +1125,8 @@
|
||||
<span class="bold"><strong>Notes:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
|
||||
need not be <code class="computeroutput"><span class="identifier">MoveConstructible</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">MoveAssignable</span></code>.
|
||||
On compilers that do not support variadic templates, the signature
|
||||
falls back to two overloads:<code class="computeroutput"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span>
|
||||
<span class="identifier">Arg</span><span class="special">></span>
|
||||
<span class="keyword">void</span> <span class="identifier">emplace</span><span class="special">(</span><span class="identifier">Arg</span><span class="special">&&</span> <span class="identifier">arg</span><span class="special">)</span></code> and <code class="computeroutput"><span class="keyword">void</span>
|
||||
<span class="identifier">emplace</span><span class="special">()</span></code>.
|
||||
On compilers that do not support rvalue references, the signature falls
|
||||
back to three overloads: taking <code class="computeroutput"><span class="keyword">const</span></code>
|
||||
and non-<code class="computeroutput"><span class="keyword">const</span></code> lvalue reference,
|
||||
and third with empty function argument list.
|
||||
On compilers that do not suppor variadic templates or rvalue references,
|
||||
this function is available in limited functionality. For details <a class="link" href="../../dependencies_and_portability/emplace_operations_in_older_compilers.html#optional_emplace_workaround">see here</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<span class="bold"><strong>Example:</strong></span>
|
||||
|
@ -0,0 +1,61 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Initialization tags</title>
|
||||
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../../../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../../../optional/reference/header__boost_optional_optional_hpp_.html" title="Header <boost/optional/optional.hpp>">
|
||||
<link rel="prev" href="../../../optional/reference/header__boost_optional_optional_hpp_.html" title="Header <boost/optional/optional.hpp>">
|
||||
<link rel="next" href="header_optional_optional_values.html" title="Optional Values">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_values.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_optional.reference.header__boost_optional_optional_hpp_.header_optional_in_place_init"></a><a class="link" href="header_optional_in_place_init.html" title="Initialization tags">Initialization
|
||||
tags</a>
|
||||
</h4></div></div></div>
|
||||
<a name="reference_in_place_init"></a><a name="reference_in_place_init_if"></a><pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">in_place_init_t</span> <span class="special">{</span> <span class="comment">/* see below */</span> <span class="special">}</span> <span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">in_place_init_t</span> <span class="identifier">in_place_init</span> <span class="special">(</span> <span class="comment">/* see below */</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">in_place_init_if_t</span> <span class="special">{</span> <span class="comment">/*see below*/</span> <span class="special">}</span> <span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">in_place_init_if_t</span> <span class="identifier">in_place_init_if</span> <span class="special">(</span> <span class="comment">/*see below*/</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
Classes <code class="computeroutput"><span class="identifier">in_place_init_t</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">in_place_init_if_t</span></code>
|
||||
are empty clsses. Their purpose is to control overload resolution in the
|
||||
initialization of optional objects. They are empty, trivially copyable
|
||||
classes with disabled default constructor.
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2003-2007 Fernando Luis Cacciola Carballal<br>Copyright © 2014-2016 Andrzej Krzemieński<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_values.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -6,7 +6,7 @@
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../../../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../../../optional/reference/header__boost_optional_optional_hpp_.html" title="Header <boost/optional/optional.hpp>">
|
||||
<link rel="prev" href="../../../optional/reference/header__boost_optional_optional_hpp_.html" title="Header <boost/optional/optional.hpp>">
|
||||
<link rel="prev" href="header_optional_in_place_init.html" title="Initialization tags">
|
||||
<link rel="next" href="header_optional_optional_refs.html" title="Optional References">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@ -20,7 +20,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_refs.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="header_optional_in_place_init.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_refs.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
@ -47,7 +47,6 @@
|
||||
|
||||
<span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">T</span><span class="special">&&</span> <span class="identifier">v</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_constructor_move_value"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="comment">// [new in 1.34]</span>
|
||||
<span class="identifier">optional</span> <span class="special">(</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">T</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">v</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_constructor_bool_value"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
<span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">optional</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_constructor_optional"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
@ -58,6 +57,10 @@
|
||||
|
||||
<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="keyword">explicit</span> <span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">optional</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&&</span> <span class="identifier">rhs</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_move_constructor_other_optional"><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="special">...</span> <span class="identifier">Args</span><span class="special">></span> <span class="keyword">explicit</span> <span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">in_place_init_t</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_in_place_init"><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="special">...</span> <span class="identifier">Args</span><span class="special">></span> <span class="keyword">explicit</span> <span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">in_place_init_if_t</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">condition</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&&...</span> <span class="identifier">args</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_in_place_init_if"><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">InPlaceFactory</span><span class="special">></span> <span class="keyword">explicit</span> <span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">InPlaceFactory</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">f</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_constructor_factory"><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">TypedInPlaceFactory</span><span class="special">></span> <span class="keyword">explicit</span> <span class="identifier">optional</span> <span class="special">(</span> <span class="identifier">TypedInPlaceFactory</span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">f</span> <span class="special">)</span> <span class="special">;</span> <a class="link" href="detailed_semantics___optional_values.html#reference_optional_constructor_factory"><span class="inlinemediaobject"><img src="../../../images/callouts/R.png" alt="R"></span></a>
|
||||
@ -135,7 +138,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_refs.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="header_optional_in_place_init.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../optional/reference/header__boost_optional_optional_hpp_.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="header_optional_optional_refs.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -28,6 +28,30 @@
|
||||
</h2></div></div></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h0"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_63"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_63">Boost
|
||||
Release 1.63</a>
|
||||
</h4>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Added two new in-place constructors. They work similarly to <code class="computeroutput"><span class="identifier">emplace</span><span class="special">()</span></code>
|
||||
functions: they initialize the contained value by perfect-forwarding the
|
||||
obtained arguments. One constructor always initializes the contained value,
|
||||
the other based on a boolean condition.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Syntax <code class="computeroutput"><span class="identifier">o</span> <span class="special">=</span>
|
||||
<span class="special">{}</span></code> now correctly un-initializes
|
||||
optional, just like in <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">optional</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12203" target="_top">Trac #12203</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12563" target="_top">Trac #12563</a>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_62"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_62">Boost
|
||||
Release 1.62</a>
|
||||
</h4>
|
||||
@ -35,7 +59,7 @@
|
||||
Fixed <a href="https://svn.boost.org/trac/boost/ticket/12179" target="_top">Trac #12179</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h1"></a>
|
||||
<a name="boost_optional.relnotes.h2"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_61"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_61">Boost
|
||||
Release 1.61</a>
|
||||
</h4>
|
||||
@ -78,7 +102,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h2"></a>
|
||||
<a name="boost_optional.relnotes.h3"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_60"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_60">Boost
|
||||
Release 1.60</a>
|
||||
</h4>
|
||||
@ -89,7 +113,7 @@
|
||||
#11203</a>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h3"></a>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_59"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_59">Boost
|
||||
Release 1.59</a>
|
||||
</h4>
|
||||
@ -103,7 +127,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h4"></a>
|
||||
<a name="boost_optional.relnotes.h5"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_58"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_58">Boost
|
||||
Release 1.58</a>
|
||||
</h4>
|
||||
@ -139,7 +163,7 @@
|
||||
</li>
|
||||
</ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h5"></a>
|
||||
<a name="boost_optional.relnotes.h6"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_57"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_57">Boost
|
||||
Release 1.57</a>
|
||||
</h4>
|
||||
@ -149,7 +173,7 @@
|
||||
to fix C++03 compile error on <code class="computeroutput"><span class="identifier">logic_error</span><span class="special">(</span><span class="string">"..."</span><span class="special">)</span></code>"</em></span>.
|
||||
</li></ul></div>
|
||||
<h4>
|
||||
<a name="boost_optional.relnotes.h6"></a>
|
||||
<a name="boost_optional.relnotes.h7"></a>
|
||||
<span class="phrase"><a name="boost_optional.relnotes.boost_release_1_56"></a></span><a class="link" href="relnotes.html#boost_optional.relnotes.boost_release_1_56">Boost
|
||||
Release 1.56</a>
|
||||
</h4>
|
||||
|
@ -55,7 +55,7 @@
|
||||
Stack Overflow question</a>) use the following way of initializing
|
||||
an optional containing no value:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">make_optional</span><span class="special">(</span><span class="keyword">false</span><span class="special">,</span> <span class="keyword">int</span><span class="special">());</span>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">optional</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="identifier">b</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_optional</span><span class="special">(</span><span class="keyword">false</span><span class="special">,</span> <span class="keyword">int</span><span class="special">());</span>
|
||||
</pre>
|
||||
<p>
|
||||
This is obviously redundant, but makes the warning disappear.
|
||||
|
@ -89,6 +89,8 @@
|
||||
and Portability</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_optional/dependencies_and_portability.html#boost_optional.dependencies_and_portability.dependencies">Dependencies</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_optional/dependencies_and_portability/emplace_operations_in_older_compilers.html">Emplace
|
||||
operations in older compilers</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_optional/dependencies_and_portability/optional_reference_binding.html">Optional
|
||||
Reference Binding</a></span></dt>
|
||||
</dl></dd>
|
||||
@ -143,7 +145,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: September 16, 2016 at 23:43:36 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: March 22, 2017 at 21:55:47 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<link rel="home" href="../../index.html" title="Boost.Optional">
|
||||
<link rel="up" href="../reference.html" title="Reference">
|
||||
<link rel="prev" href="../../boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html" title="Header <boost/optional/optional_fwd.hpp>">
|
||||
<link rel="next" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_values.html" title="Optional Values">
|
||||
<link rel="next" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_in_place_init.html" title="Initialization tags">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@ -20,7 +20,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_values.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="../../boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_in_place_init.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
@ -35,6 +35,12 @@
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">in_place_init_t</span> <span class="special">{</span> <span class="comment">/* see below */</span> <span class="special">}</span> <span class="special">;</span> <a class="link" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_in_place_init.html#reference_in_place_init"><span class="inlinemediaobject"><img src="../../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="keyword">const</span> <span class="identifier">in_place_init_t</span> <span class="identifier">in_place_init</span> <span class="special">(</span> <span class="comment">/* see below */</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">in_place_init_if_t</span> <span class="special">{</span> <span class="comment">/*see below*/</span> <span class="special">}</span> <span class="special">;</span> <a class="link" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_in_place_init.html#reference_in_place_init_if"><span class="inlinemediaobject"><img src="../../images/callouts/R.png" alt="R"></span></a>
|
||||
<span class="keyword">const</span> <span class="identifier">in_place_init_if_t</span> <span class="identifier">in_place_init_if</span> <span class="special">(</span> <span class="comment">/*see below*/</span> <span class="special">)</span> <span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">optional</span> <span class="special">;</span> <a class="link" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_values.html#reference_operator_template"><span class="inlinemediaobject"><img src="../../images/callouts/R.png" alt="R"></span></a>
|
||||
|
||||
@ -95,7 +101,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../../boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_optional_values.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="../../boost_optional/reference/header__boost_optional_optional_fwd_hpp_.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../../boost_optional/reference/header__boost_optional_optional_hpp_/header_optional_in_place_init.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -96,4 +96,21 @@
|
||||
|
||||
#endif // defined(__GNUC__)
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) && !defined(__SUNPRO_CC)
|
||||
// this condition is a copy paste from is_constructible.hpp
|
||||
// I also disable SUNPRO, as it seems not to support type_traits correctly
|
||||
#else
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
#endif
|
||||
|
||||
#if defined __SUNPRO_CC
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif (defined _MSC_FULL_VER) && (_MSC_FULL_VER < 190023026)
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif defined BOOST_GCC && !defined BOOST_GCC_CXX11
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#elif defined BOOST_GCC_VERSION && BOOST_GCC_VERSION < 40800
|
||||
# define BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
#endif
|
||||
|
||||
#endif // header guard
|
||||
|
@ -44,6 +44,23 @@ BOOST_DEDUCED_TYPENAME boost::remove_reference<T>::type& forward_reference(T&& r
|
||||
|
||||
#endif // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_const_integral
|
||||
{
|
||||
static const bool value = boost::is_const<T>::value && boost::is_integral<T>::value;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_const_integral_bad_for_conversion
|
||||
{
|
||||
#if (!defined BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES) && (defined BOOST_OPTIONAL_CONFIG_NO_PROPER_CONVERT_FROM_CONST_INT)
|
||||
static const bool value = boost::is_const<T>::value && boost::is_integral<T>::value;
|
||||
#else
|
||||
static const bool value = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class From>
|
||||
void prevent_assignment_from_false_const_integral()
|
||||
{
|
||||
@ -51,12 +68,13 @@ void prevent_assignment_from_false_const_integral()
|
||||
#ifdef BOOST_OPTIONAL_CONFIG_NO_PROPER_ASSIGN_FROM_CONST_INT
|
||||
// MSVC compiler without rvalue refernces: we need to disable the asignment from
|
||||
// const integral lvalue reference, as it may be an invalid temporary
|
||||
BOOST_STATIC_ASSERT_MSG(!(boost::is_const<From>::value && boost::is_integral<From>::value),
|
||||
BOOST_STATIC_ASSERT_MSG(!is_const_integral<From>::value,
|
||||
"binding const lvalue references to integral types is disabled in this compiler");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
struct is_optional_
|
||||
{
|
||||
@ -75,6 +93,21 @@ struct is_no_optional
|
||||
static const bool value = !is_optional_<BOOST_DEDUCED_TYPENAME boost::decay<T>::type>::value;
|
||||
};
|
||||
|
||||
|
||||
template <class T, class U>
|
||||
struct is_same_decayed
|
||||
{
|
||||
static const bool value = ::boost::is_same<T, BOOST_DEDUCED_TYPENAME ::boost::remove_reference<U>::type>::value
|
||||
|| ::boost::is_same<T, const BOOST_DEDUCED_TYPENAME ::boost::remove_reference<U>::type>::value;
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct no_unboxing_cond
|
||||
{
|
||||
static const bool value = is_no_optional<U>::value && !is_same_decayed<T, U>::value;
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class T>
|
||||
@ -94,13 +127,21 @@ public:
|
||||
optional(none_t) BOOST_NOEXCEPT : ptr_() {}
|
||||
|
||||
template <class U>
|
||||
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.get_ptr()) {}
|
||||
|
||||
|
||||
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.ptr_; return *this; }
|
||||
// the following two implement a 'conditionally explicit' constructor: condition is a hack for buggy compilers with srewed conversion construction from const int
|
||||
template <class U>
|
||||
optional& operator=(const optional<U&>& rhs) BOOST_NOEXCEPT { ptr_ = rhs.ptr_; return *this; }
|
||||
explicit optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(rhs)) {}
|
||||
|
||||
template <class U>
|
||||
optional(U& rhs, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::is_same_decayed<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value>::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(rhs)) {}
|
||||
|
||||
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
||||
template <class U>
|
||||
optional& operator=(const optional<U&>& rhs) BOOST_NOEXCEPT { ptr_ = rhs.get_ptr(); return *this; }
|
||||
optional& operator=(none_t) BOOST_NOEXCEPT { ptr_ = 0; return *this; }
|
||||
|
||||
|
||||
@ -121,8 +162,10 @@ public:
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
optional(T&& /* rhs */) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
||||
|
||||
template <class R>
|
||||
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::no_unboxing_cond<T, R> >::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
||||
|
||||
template <class R>
|
||||
@ -154,19 +197,26 @@ public:
|
||||
|
||||
#else // BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
|
||||
// the following two implement a 'conditionally explicit' constructor
|
||||
template <class U>
|
||||
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT : ptr_(boost::addressof(v)) { }
|
||||
explicit optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && detail::is_const_integral_bad_for_conversion<U>::value >::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(v)) { }
|
||||
|
||||
template <class U>
|
||||
optional(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if_c<detail::no_unboxing_cond<T, U>::value && !detail::is_const_integral_bad_for_conversion<U>::value >::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(v)) { }
|
||||
|
||||
template <class U>
|
||||
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
||||
optional(bool cond, U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT : ptr_(cond ? boost::addressof(v) : 0) {}
|
||||
|
||||
template <class U>
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, optional<T&>&>::type
|
||||
operator=(U& v) BOOST_NOEXCEPT
|
||||
{
|
||||
detail::prevent_assignment_from_false_const_integral<U>();
|
||||
ptr_ = boost::addressof(v); return *this;
|
||||
}
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U>, optional<T&>&>::type
|
||||
operator=(U& v) BOOST_NOEXCEPT
|
||||
{
|
||||
detail::prevent_assignment_from_false_const_integral<U>();
|
||||
ptr_ = boost::addressof(v); return *this;
|
||||
}
|
||||
|
||||
template <class U>
|
||||
void emplace(U& v, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<U> >::type* = 0) BOOST_NOEXCEPT
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2014, 2015 Andrzej Krzemienski.
|
||||
// Copyright (C) 2014 - 2016 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
|
||||
@ -56,6 +56,31 @@
|
||||
#include <boost/optional/detail/old_optional_implementation.hpp>
|
||||
#else
|
||||
namespace boost {
|
||||
|
||||
namespace optional_ns {
|
||||
|
||||
// a tag for in-place initialization of contained value
|
||||
struct in_place_init_t
|
||||
{
|
||||
struct init_tag{};
|
||||
explicit in_place_init_t(init_tag){}
|
||||
};
|
||||
const in_place_init_t in_place_init ((in_place_init_t::init_tag()));
|
||||
|
||||
// a tag for conditional in-place initialization of contained value
|
||||
struct in_place_init_if_t
|
||||
{
|
||||
struct init_tag{};
|
||||
explicit in_place_init_if_t(init_tag){}
|
||||
};
|
||||
const in_place_init_if_t in_place_init_if ((in_place_init_if_t::init_tag()));
|
||||
|
||||
} // namespace optional_ns
|
||||
|
||||
using optional_ns::in_place_init_t;
|
||||
using optional_ns::in_place_init;
|
||||
using optional_ns::in_place_init_if_t;
|
||||
using optional_ns::in_place_init_if;
|
||||
|
||||
namespace optional_detail {
|
||||
|
||||
@ -338,51 +363,179 @@ class optional_base : public optional_tag
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
// Constructs in-place
|
||||
// upon exception *this is always uninitialized
|
||||
template<class... Args>
|
||||
void construct ( in_place_init_t, Args&&... args )
|
||||
{
|
||||
::new (m_storage.address()) value_type( boost::forward<Args>(args)... ) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
void emplace_assign ( Args&&... args )
|
||||
{
|
||||
destroy();
|
||||
::new (m_storage.address()) value_type( boost::forward<Args>(args)... );
|
||||
m_initialized = true ;
|
||||
}
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init, boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
explicit optional_base ( in_place_init_t, Args&&... args )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
construct(in_place_init, boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
explicit optional_base ( in_place_init_if_t, bool cond, Args&&... args )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init, boost::forward<Args>(args)...);
|
||||
}
|
||||
#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
template<class Arg>
|
||||
void emplace_assign ( Arg&& arg )
|
||||
void construct ( in_place_init_t, Arg&& arg )
|
||||
{
|
||||
destroy();
|
||||
::new (m_storage.address()) value_type( boost::forward<Arg>(arg) );
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
void emplace_assign ()
|
||||
void construct ( in_place_init_t )
|
||||
{
|
||||
destroy();
|
||||
::new (m_storage.address()) value_type();
|
||||
m_initialized = true ;
|
||||
}
|
||||
#else
|
||||
|
||||
template<class Arg>
|
||||
void emplace_assign ( const Arg& arg )
|
||||
void emplace_assign ( Arg&& arg )
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init, boost::forward<Arg>(arg)) ;
|
||||
}
|
||||
|
||||
void emplace_assign ()
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init) ;
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_t, Arg&& arg )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
construct(in_place_init, boost::forward<Arg>(arg));
|
||||
}
|
||||
|
||||
explicit optional_base ( in_place_init_t )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
construct(in_place_init);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_if_t, bool cond, Arg&& arg )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init, boost::forward<Arg>(arg));
|
||||
}
|
||||
|
||||
explicit optional_base ( in_place_init_if_t, bool cond )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template<class Arg>
|
||||
void construct ( in_place_init_t, const Arg& arg )
|
||||
{
|
||||
::new (m_storage.address()) value_type( arg );
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
void construct ( in_place_init_t, Arg& arg )
|
||||
{
|
||||
::new (m_storage.address()) value_type( arg );
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
void construct ( in_place_init_t )
|
||||
{
|
||||
::new (m_storage.address()) value_type();
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
void emplace_assign ( const Arg& arg )
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
void emplace_assign ( Arg& arg )
|
||||
{
|
||||
destroy();
|
||||
::new (m_storage.address()) value_type( arg );
|
||||
m_initialized = true ;
|
||||
}
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
void emplace_assign ()
|
||||
{
|
||||
destroy();
|
||||
::new (m_storage.address()) value_type();
|
||||
m_initialized = true ;
|
||||
}
|
||||
{
|
||||
destroy();
|
||||
construct(in_place_init);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_t, const Arg& arg )
|
||||
: m_initialized(false)
|
||||
{
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_t, Arg& arg )
|
||||
: m_initialized(false)
|
||||
{
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
explicit optional_base ( in_place_init_t )
|
||||
: m_initialized(false)
|
||||
{
|
||||
construct(in_place_init);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_if_t, bool cond, const Arg& arg )
|
||||
: m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional_base ( in_place_init_if_t, bool cond, Arg& arg )
|
||||
: m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init, arg);
|
||||
}
|
||||
|
||||
explicit optional_base ( in_place_init_if_t, bool cond )
|
||||
: m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(in_place_init);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||
@ -574,30 +727,36 @@ class optional_base : public optional_tag
|
||||
template <typename U>
|
||||
struct is_optional_related
|
||||
: boost::conditional< boost::is_base_of<optional_detail::optional_tag, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
|
||||
|| boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<U>::type, none_t>::value,
|
||||
|| boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<U>::type, none_t>::value
|
||||
|| boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<U>::type, in_place_init_t>::value
|
||||
|| boost::is_same<BOOST_DEDUCED_TYPENAME boost::decay<U>::type, in_place_init_if_t>::value,
|
||||
boost::true_type, boost::false_type>::type
|
||||
{};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) && !defined(__SUNPRO_CC)
|
||||
// this condition is a copy paste from is_constructible.hpp
|
||||
// I also disable SUNPRO, as it seems not to support type_traits correctly
|
||||
#if !defined(BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_convertible_to_T_or_factory
|
||||
: boost::conditional< boost::is_base_of<boost::in_place_factory_base, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
|
||||
|| boost::is_base_of<boost::typed_in_place_factory_base, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value
|
||||
|| boost::is_constructible<T, U&&>::value
|
||||
|| (boost::is_constructible<T, U&&>::value && !boost::is_same<T, BOOST_DEDUCED_TYPENAME boost::decay<U>::type>::value)
|
||||
, boost::true_type, boost::false_type>::type
|
||||
{};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_optional_constructible : boost::is_constructible<T, U>
|
||||
{};
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
|
||||
template <typename, typename>
|
||||
struct is_convertible_to_T_or_factory : boost::true_type
|
||||
{};
|
||||
|
||||
template <typename T, typename U>
|
||||
struct is_optional_constructible : boost::true_type
|
||||
{};
|
||||
|
||||
#endif // is_convertible condition
|
||||
|
||||
template <typename T, typename U>
|
||||
@ -657,7 +816,11 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Requires a valid conversion from U to T.
|
||||
// Can throw if T::T(U const&) does
|
||||
template<class U>
|
||||
explicit optional ( optional<U> const& rhs )
|
||||
explicit optional ( optional<U> const& rhs
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U const&> >::type* = 0
|
||||
#endif
|
||||
)
|
||||
:
|
||||
base()
|
||||
{
|
||||
@ -670,7 +833,11 @@ class optional : public optional_detail::optional_base<T>
|
||||
// Requires a valid conversion from U to T.
|
||||
// Can throw if T::T(U&&) does
|
||||
template<class U>
|
||||
explicit optional ( optional<U> && rhs )
|
||||
explicit optional ( optional<U> && rhs
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
,typename boost::enable_if< optional_detail::is_optional_constructible<T, U> >::type* = 0
|
||||
#endif
|
||||
)
|
||||
:
|
||||
base()
|
||||
{
|
||||
@ -789,6 +956,19 @@ class optional : public optional_detail::optional_base<T>
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
|
||||
// Assigns from a T (deep-moves/copies the rhs value)
|
||||
template <typename T_>
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<boost::is_same<T, BOOST_DEDUCED_TYPENAME boost::decay<T_>::type>, optional&>::type
|
||||
operator= ( T_&& val )
|
||||
{
|
||||
this->assign( boost::forward<T_>(val) ) ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// Assigns from a T (deep-copies the rhs value)
|
||||
// Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
|
||||
optional& operator= ( argument_type val )
|
||||
@ -796,7 +976,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
this->assign( val ) ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
// Assigns from a T (deep-moves the rhs value)
|
||||
optional& operator= ( rval_reference_type val )
|
||||
@ -805,7 +985,9 @@ class optional : public optional_detail::optional_base<T>
|
||||
return *this ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
|
||||
// Assigns from a "none"
|
||||
// Which destroys the current value, if any, leaving this UNINITIALIZED
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
@ -820,9 +1002,20 @@ class optional : public optional_detail::optional_base<T>
|
||||
// upon exception *this is always uninitialized
|
||||
template<class... Args>
|
||||
void emplace ( Args&&... args )
|
||||
{
|
||||
this->emplace_assign( boost::forward<Args>(args)... );
|
||||
}
|
||||
{
|
||||
this->emplace_assign( boost::forward<Args>(args)... );
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
explicit optional ( in_place_init_t, Args&&... args )
|
||||
: base( in_place_init, boost::forward<Args>(args)... )
|
||||
{}
|
||||
|
||||
template<class... Args>
|
||||
explicit optional ( in_place_init_if_t, bool cond, Args&&... args )
|
||||
: base( in_place_init_if, cond, boost::forward<Args>(args)... )
|
||||
{}
|
||||
|
||||
#elif (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
template<class Arg>
|
||||
void emplace ( Arg&& arg )
|
||||
@ -834,6 +1027,24 @@ class optional : public optional_detail::optional_base<T>
|
||||
{
|
||||
this->emplace_assign();
|
||||
}
|
||||
|
||||
template<class Args>
|
||||
explicit optional ( in_place_init_t, Args&& args )
|
||||
: base( in_place_init, boost::forward<Args>(args) )
|
||||
{}
|
||||
|
||||
explicit optional ( in_place_init_t )
|
||||
: base( in_place_init )
|
||||
{}
|
||||
|
||||
template<class Args>
|
||||
explicit optional ( in_place_init_if_t, bool cond, Args&& args )
|
||||
: base( in_place_init_if, cond, boost::forward<Args>(args) )
|
||||
{}
|
||||
|
||||
explicit optional ( in_place_init_if_t, bool cond )
|
||||
: base( in_place_init_if, cond )
|
||||
{}
|
||||
#else
|
||||
template<class Arg>
|
||||
void emplace ( const Arg& arg )
|
||||
@ -851,6 +1062,34 @@ class optional : public optional_detail::optional_base<T>
|
||||
{
|
||||
this->emplace_assign();
|
||||
}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional ( in_place_init_t, const Arg& arg )
|
||||
: base( in_place_init, arg )
|
||||
{}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional ( in_place_init_t, Arg& arg )
|
||||
: base( in_place_init, arg )
|
||||
{}
|
||||
|
||||
explicit optional ( in_place_init_t )
|
||||
: base( in_place_init )
|
||||
{}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional ( in_place_init_if_t, bool cond, const Arg& arg )
|
||||
: base( in_place_init_if, cond, arg )
|
||||
{}
|
||||
|
||||
template<class Arg>
|
||||
explicit optional ( in_place_init_if_t, bool cond, Arg& arg )
|
||||
: base( in_place_init_if, cond, arg )
|
||||
{}
|
||||
|
||||
explicit optional ( in_place_init_if_t, bool cond )
|
||||
: base( in_place_init_if, cond )
|
||||
{}
|
||||
#endif
|
||||
|
||||
void swap( optional & arg )
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Boost.Optional Library test Jamfile
|
||||
#
|
||||
# Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
# Copyright (C) 2014, 2015 Andrzej Krzemienski
|
||||
# Copyright (C) 2014 - 2016 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
|
||||
@ -20,6 +20,8 @@ import testing ;
|
||||
[ run optional_test.cpp ]
|
||||
[ run optional_test_swap.cpp ]
|
||||
[ run optional_test_conversions_from_U.cpp ]
|
||||
[ run optional_test_convert_from_T.cpp ]
|
||||
[ run optional_test_empty_braces.cpp ]
|
||||
[ run optional_test_tie.cpp ]
|
||||
[ run optional_test_ref_assign_portable_minimum.cpp ]
|
||||
[ run optional_test_ref_assign_mutable_int.cpp ]
|
||||
@ -40,7 +42,7 @@ import testing ;
|
||||
[ run optional_test_emplace.cpp ]
|
||||
[ run optional_test_minimum_requirements.cpp ]
|
||||
[ run optional_test_msvc_bug_workaround.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_value_ctor.cpp ]
|
||||
[ compile optional_test_sfinae_friendly_ctor.cpp ]
|
||||
[ compile-fail optional_test_ref_convert_assign_const_int_prevented.cpp ]
|
||||
[ compile-fail optional_test_fail1.cpp ]
|
||||
[ compile-fail optional_test_fail3a.cpp ]
|
||||
|
@ -152,21 +152,21 @@ bool X::pending_assign = false ;
|
||||
bool X::throw_on_copy = false ;
|
||||
bool X::throw_on_assign = false ;
|
||||
|
||||
inline void set_pending_copy ( X const* x ) { X::pending_copy = true ; }
|
||||
inline void set_pending_dtor ( X const* x ) { X::pending_dtor = true ; }
|
||||
inline void set_pending_assign ( X const* x ) { X::pending_assign = true ; }
|
||||
inline void set_throw_on_copy ( X const* x ) { X::throw_on_copy = true ; }
|
||||
inline void set_throw_on_assign ( X const* x ) { X::throw_on_assign = true ; }
|
||||
inline void reset_throw_on_copy ( X const* x ) { X::throw_on_copy = false ; }
|
||||
inline void reset_throw_on_assign ( X const* x ) { X::throw_on_assign = false ; }
|
||||
inline void check_is_pending_copy ( X const* x ) { BOOST_TEST( X::pending_copy ) ; }
|
||||
inline void check_is_pending_dtor ( X const* x ) { BOOST_TEST( X::pending_dtor ) ; }
|
||||
inline void check_is_pending_assign ( X const* x ) { BOOST_TEST( X::pending_assign ) ; }
|
||||
inline void check_is_not_pending_copy ( X const* x ) { BOOST_TEST( !X::pending_copy ) ; }
|
||||
inline void check_is_not_pending_dtor ( X const* x ) { BOOST_TEST( !X::pending_dtor ) ; }
|
||||
inline void check_is_not_pending_assign( X const* x ) { BOOST_TEST( !X::pending_assign ) ; }
|
||||
inline void check_instance_count ( int c, X const* x ) { BOOST_TEST( X::count == c ) ; }
|
||||
inline int get_instance_count ( X const* x ) { return X::count ; }
|
||||
inline void set_pending_copy ( X const* ) { X::pending_copy = true ; }
|
||||
inline void set_pending_dtor ( X const* ) { X::pending_dtor = true ; }
|
||||
inline void set_pending_assign ( X const* ) { X::pending_assign = true ; }
|
||||
inline void set_throw_on_copy ( X const* ) { X::throw_on_copy = true ; }
|
||||
inline void set_throw_on_assign ( X const* ) { X::throw_on_assign = true ; }
|
||||
inline void reset_throw_on_copy ( X const* ) { X::throw_on_copy = false ; }
|
||||
inline void reset_throw_on_assign ( X const* ) { X::throw_on_assign = false ; }
|
||||
inline void check_is_pending_copy ( X const* ) { BOOST_TEST( X::pending_copy ) ; }
|
||||
inline void check_is_pending_dtor ( X const* ) { BOOST_TEST( X::pending_dtor ) ; }
|
||||
inline void check_is_pending_assign ( X const* ) { BOOST_TEST( X::pending_assign ) ; }
|
||||
inline void check_is_not_pending_copy ( X const* ) { BOOST_TEST( !X::pending_copy ) ; }
|
||||
inline void check_is_not_pending_dtor ( X const* ) { BOOST_TEST( !X::pending_dtor ) ; }
|
||||
inline void check_is_not_pending_assign( X const* ) { BOOST_TEST( !X::pending_assign ) ; }
|
||||
inline void check_instance_count ( int c, X const* ) { BOOST_TEST( X::count == c ) ; }
|
||||
inline int get_instance_count ( X const* ) { return X::count ; }
|
||||
|
||||
inline void set_pending_copy (...) {}
|
||||
inline void set_pending_dtor (...) {}
|
||||
|
70
test/optional_test_convert_from_T.cpp
Normal file
70
test/optional_test_convert_from_T.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
// 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/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/none.hpp"
|
||||
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
|
||||
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
template <typename U>
|
||||
struct superconv
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
template <typename T>
|
||||
superconv(T&&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
#else
|
||||
template <typename T>
|
||||
superconv(const T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
template <typename T>
|
||||
superconv( T&) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }
|
||||
#endif
|
||||
|
||||
superconv() {}
|
||||
};
|
||||
|
||||
void test_optional_of_superconverting_T() // compile-time test
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||||
superconv<optional<int> > s;
|
||||
superconv<optional<int> > & rs = s;
|
||||
optional<superconv<optional<int> > > os = rs;
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_optional_optional_T()
|
||||
{
|
||||
optional<int> oi1 (1), oiN;
|
||||
optional< optional<int> > ooi1 (oi1), ooiN(oiN);
|
||||
|
||||
BOOST_TEST(ooi1);
|
||||
BOOST_TEST(*ooi1);
|
||||
BOOST_TEST_EQ(**ooi1, 1);
|
||||
|
||||
BOOST_TEST(ooiN);
|
||||
BOOST_TEST(!*ooiN);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_optional_optional_T();
|
||||
test_optional_of_superconverting_T();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -23,6 +23,8 @@
|
||||
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
using boost::in_place_init;
|
||||
using boost::in_place_init_if;
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
@ -87,6 +89,109 @@ void test_emplace()
|
||||
BOOST_TEST(7 == o->which_ctor);
|
||||
}
|
||||
|
||||
void test_in_place_ctor()
|
||||
{
|
||||
int i = 0;
|
||||
double d = 0.0;
|
||||
const std::string cs;
|
||||
std::string ms;
|
||||
|
||||
{
|
||||
optional<Guard> o (in_place_init);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(0 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, i, 2.0);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(1 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, 1, d);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(2 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, 1, 2.0);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(3 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, i, d);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(4 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, cs);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(5 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, ms);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(6 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, std::string());
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(7 == o->which_ctor);
|
||||
}
|
||||
}
|
||||
|
||||
void test_in_place_if_ctor()
|
||||
{
|
||||
int i = 0;
|
||||
double d = 0.0;
|
||||
const std::string cs;
|
||||
std::string ms;
|
||||
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(0 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, i, 2.0);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(1 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, 1, d);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(2 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, 1, 2.0);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(3 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, i, d);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(4 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, cs);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(5 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, ms);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(6 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, true, std::string());
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(7 == o->which_ctor);
|
||||
}
|
||||
|
||||
{
|
||||
optional<Guard> o (in_place_init_if, false, 1, 2.0);
|
||||
BOOST_TEST(!o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -112,6 +217,24 @@ void test_no_moves_on_emplacement()
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
|
||||
void test_no_moves_on_in_place_ctor()
|
||||
{
|
||||
try {
|
||||
optional<ThrowOnMove> o (in_place_init, 1);
|
||||
BOOST_TEST(o);
|
||||
|
||||
optional<ThrowOnMove> p (in_place_init_if, true, 1);
|
||||
BOOST_TEST(p);
|
||||
|
||||
optional<ThrowOnMove> q (in_place_init_if, false, 1);
|
||||
BOOST_TEST(!q);
|
||||
}
|
||||
catch (...) {
|
||||
BOOST_TEST(false);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct Thrower
|
||||
@ -158,6 +281,7 @@ void test_no_assignment_on_emplacement()
|
||||
}
|
||||
|
||||
namespace no_rvalue_refs {
|
||||
|
||||
class Guard
|
||||
{
|
||||
public:
|
||||
@ -188,19 +312,78 @@ void test_emplace()
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(6 == o->which_ctor);
|
||||
}
|
||||
}
|
||||
|
||||
void test_in_place_ctor()
|
||||
{
|
||||
const std::string cs;
|
||||
std::string ms;
|
||||
|
||||
{
|
||||
optional<Guard> o (in_place_init);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(0 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, cs);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(5 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> o (in_place_init, ms);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(6 == o->which_ctor);
|
||||
}
|
||||
}
|
||||
|
||||
void test_in_place_if_ctor()
|
||||
{
|
||||
const std::string cs;
|
||||
std::string ms;
|
||||
|
||||
{
|
||||
optional<Guard> n (in_place_init_if, false);
|
||||
BOOST_TEST(!n);
|
||||
|
||||
optional<Guard> o (in_place_init_if, true);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(0 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> n (in_place_init_if, false, cs);
|
||||
BOOST_TEST(!n);
|
||||
|
||||
optional<Guard> o (in_place_init_if, true, cs);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(5 == o->which_ctor);
|
||||
}
|
||||
{
|
||||
optional<Guard> n (in_place_init_if, false, ms);
|
||||
BOOST_TEST(!n);
|
||||
|
||||
optional<Guard> o (in_place_init_if, true, ms);
|
||||
BOOST_TEST(o);
|
||||
BOOST_TEST(6 == o->which_ctor);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace no_rvalue_ref
|
||||
|
||||
int main()
|
||||
{
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES) && (!defined BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
test_emplace();
|
||||
test_in_place_ctor();
|
||||
test_in_place_if_ctor();
|
||||
#endif
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES)
|
||||
test_no_moves_on_emplacement();
|
||||
test_no_moves_on_in_place_ctor();
|
||||
#endif
|
||||
test_clear_on_throw();
|
||||
test_no_assignment_on_emplacement();
|
||||
no_rvalue_refs::test_emplace();
|
||||
no_rvalue_refs::test_in_place_ctor();
|
||||
no_rvalue_refs::test_in_place_if_ctor();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
57
test/optional_test_empty_braces.cpp
Normal file
57
test/optional_test_empty_braces.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2016 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/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
|
||||
|
||||
using boost::optional;
|
||||
|
||||
struct Value
|
||||
{
|
||||
explicit Value(int) {}
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
template <typename T>
|
||||
void test_brace_init()
|
||||
{
|
||||
optional<T> o = {};
|
||||
BOOST_TEST(!o);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_brace_assign()
|
||||
{
|
||||
optional<T> o;
|
||||
o = {};
|
||||
BOOST_TEST(!o);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX
|
||||
test_brace_init<int>();
|
||||
test_brace_init<Value>();
|
||||
test_brace_assign<int>();
|
||||
test_brace_assign<Value>();
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -39,6 +39,7 @@ int main()
|
||||
{
|
||||
test_optional_ref_assignment<ScopeGuard>();
|
||||
test_optional_ref_assignment<Abstract>();
|
||||
test_optional_ref_assignment< optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ int main()
|
||||
test_all_const_cases<int>();
|
||||
test_all_const_cases<ScopeGuard>();
|
||||
test_all_const_cases<Abstract>();
|
||||
test_all_const_cases< optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
// akrzemi1@gmail.com
|
||||
//
|
||||
#include "boost/optional.hpp"
|
||||
#include "boost/core/ignore_unused.hpp"
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//
|
||||
@ -18,6 +19,7 @@
|
||||
void optional_reference__test_no_init_from_Trefref()
|
||||
{
|
||||
boost::optional<const int&> opt = int(3);
|
||||
boost::ignore_unused(opt);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2014, andrzej Krzemienski.
|
||||
// Copyright (C) 2014, 2016 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
|
||||
@ -10,6 +10,7 @@
|
||||
// akrzemi1@gmail.com
|
||||
//
|
||||
#include "boost/optional.hpp"
|
||||
#include "boost/core/ignore_unused.hpp"
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
//
|
||||
@ -18,6 +19,7 @@
|
||||
void optional_reference__test_no_init_from_Urefref()
|
||||
{
|
||||
boost::optional<const int&> opt = long(3);
|
||||
boost::ignore_unused(opt);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -430,6 +430,23 @@ void test_swap()
|
||||
BOOST_TEST(boost::addressof(*o2_) == boost::addressof(v1));
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
void test_convertability_of_compatible_reference_types()
|
||||
{
|
||||
typename concrete_type_of<T>::type v1(1);
|
||||
optional<T&> oN, o1(v1);
|
||||
optional<U&> uN(oN), u1(o1);
|
||||
BOOST_TEST(!uN);
|
||||
BOOST_TEST(u1);
|
||||
BOOST_TEST(boost::addressof(*u1) == boost::addressof(*o1));
|
||||
|
||||
uN = o1;
|
||||
u1 = oN;
|
||||
BOOST_TEST(!u1);
|
||||
BOOST_TEST(uN);
|
||||
BOOST_TEST(boost::addressof(*uN) == boost::addressof(*o1));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_optional_ref()
|
||||
{
|
||||
@ -465,10 +482,18 @@ int main()
|
||||
test_optional_ref<int>();
|
||||
test_optional_ref<ScopeGuard>();
|
||||
test_optional_ref<Abstract>();
|
||||
test_optional_ref< optional<int> >();
|
||||
|
||||
test_optional_const_ref<int>();
|
||||
test_optional_const_ref<ScopeGuard>();
|
||||
test_optional_const_ref<Abstract>();
|
||||
test_optional_const_ref< optional<int> >();
|
||||
|
||||
test_convertability_of_compatible_reference_types<int, const int>();
|
||||
test_convertability_of_compatible_reference_types<Impl, Abstract>();
|
||||
test_convertability_of_compatible_reference_types<Impl, const Abstract>();
|
||||
test_convertability_of_compatible_reference_types<const Impl, const Abstract>();
|
||||
test_convertability_of_compatible_reference_types<optional<int>, const optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
49
test/optional_test_sfinae_friendly_ctor.cpp
Normal file
49
test/optional_test_sfinae_friendly_ctor.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
// 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/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
using boost::optional;
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)
|
||||
|
||||
struct X {};
|
||||
struct Y {};
|
||||
|
||||
struct Resource
|
||||
{
|
||||
explicit Resource(const X&) {}
|
||||
};
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<Resource, const X&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<Resource, const Y&>::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const X&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const Y&>::value ));
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, optional<int> >::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, optional< optional<int> > >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible< optional< optional<int> >, const optional<int>& >::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible< optional<int>, const optional< optional<int> >& >::value ));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const optional<X>&>::value ));
|
||||
BOOST_STATIC_ASSERT(( !boost::is_constructible<optional<Resource>, const optional<Y>&>::value ));
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
int main() { }
|
@ -1,38 +0,0 @@
|
||||
// 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/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
using boost::optional;
|
||||
|
||||
#if (!defined BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT)
|
||||
|
||||
struct X {};
|
||||
struct Y {};
|
||||
|
||||
struct Resource
|
||||
{
|
||||
explicit Resource(const X&) {}
|
||||
};
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<Resource, const X&>::value));
|
||||
BOOST_STATIC_ASSERT((!boost::is_constructible<Resource, const Y&>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT(( boost::is_constructible<optional<Resource>, const X&>::value));
|
||||
BOOST_STATIC_ASSERT((!boost::is_constructible<optional<Resource>, const Y&>::value));
|
||||
|
||||
#endif
|
||||
|
||||
int main() { }
|
@ -15,7 +15,7 @@
|
||||
|
||||
#if (defined BOOST_NO_CXX11_RVALUE_REFERENCES) || (!defined BOOST_OPTIONAL_CONFIG_NO_LEGAL_CONVERT_FROM_REF)
|
||||
|
||||
static_assert(false, "failed as requested");
|
||||
# error "failed as requested"
|
||||
|
||||
#else
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
#ifndef BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP
|
||||
#define BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
struct ScopeGuard // no copy/move ctor/assign
|
||||
{
|
||||
int val_;
|
||||
@ -74,13 +76,23 @@ struct has_arrow<int>
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct has_arrow< boost::optional<int> >
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
int& val(int& i) { return i; }
|
||||
int& val(Abstract& a) { return a.val(); }
|
||||
int& val(Impl& a) { return a.val(); }
|
||||
int& val(ScopeGuard& g) { return g.val(); }
|
||||
template <typename T> int& val(T& o) { return *o; }
|
||||
|
||||
const int& val(const int& i) { return i; }
|
||||
const int& val(const Abstract& a) { return a.val(); }
|
||||
const int& val(const Impl& a) { return a.val(); }
|
||||
const int& val(const ScopeGuard& g) { return g.val(); }
|
||||
template <typename T> const int& val(const T& o) { return *o; }
|
||||
|
||||
bool operator==(const Abstract& l, const Abstract& r) { return l.val() == r.val(); }
|
||||
bool operator==(const ScopeGuard& l, const ScopeGuard& r) { return l.val() == r.val(); }
|
||||
|
Reference in New Issue
Block a user