diff --git a/doc/html/boost_optional/detailed_semantics.html b/doc/html/boost_optional/detailed_semantics.html
index 9163af0..77b8815 100644
--- a/doc/html/boost_optional/detailed_semantics.html
+++ b/doc/html/boost_optional/detailed_semantics.html
@@ -72,7 +72,7 @@
- optional<T>::optional();
+ optional<T>::optional() noexcept;
-
@@ -82,11 +82,7 @@
Postconditions:
*this
is uninitialized.
-
- Throws: Nothing.
-
--
- Notes: T's default constructor is not
- called.
+ Notes: T's default constructor is not called.
-
Example:
@@ -99,7 +95,7 @@
- optional<T>::optional( none_t );
+ optional<T>::optional( none_t ) noexcept;
-
@@ -109,9 +105,6 @@
-
Postconditions:
*this
is uninitialized.
--
- Throws: Nothing.
-
-
Notes:
T
's
default constructor is not called.
@@ -132,12 +125,16 @@
optional<T
(not a ref)>::optional( T const& v )
+-
+ Requires:
is_copy_constructible<T>::value
+ is true
.
+
-
Effect: Directly-Constructs an
optional
.
-
Postconditions:
*this
is initialized
- and its value is acopy of v
.
+ and its value is a copy of v
.
-
Throws: Whatever
T::T(
@@ -193,6 +190,58 @@
+
+
+
+
+ optional<T
(not a ref)>::optional( T&&
+ v )
+
+
+
+
+
+
+ optional<T&>::optional( T&& ref ) = delete
+
+-
+ Notes: This constructor is deleted
+
@@ -229,6 +278,10 @@
optional<T
(not a ref)>::optional( optional const& rhs );
+-
+ Requires:
is_copy_constructible<T>::value
+ is true
.
+
-
Effect: Copy-Constructs an
optional
.
@@ -320,6 +373,116 @@
+
+
+
+
+ optional<T
(not a ref)>::optional( optional&& rhs
+ ) noexcept(
see below);
+
+
+
+
+
+
+ optional<T&>::optional( optional &&
+ rhs );
+
+
@@ -368,6 +531,52 @@
+
+
+
+
+ template<U> explicit optional<T
+ (not a ref)>::optional( optional<U>&&
+ rhs );
+
+
@@ -511,6 +720,66 @@
+
+
+
+
+ optional&
+ optional<T
(not a ref)>::operator= ( T&& rhs
+ ) ;
+
+
+
+
+
+
+ optional<T&>&
+ optional<T&>::operator= ( T&&
+ rhs )
+ = delete;
+
+-
+ Notes: This assignment operator is deleted.
+
@@ -613,6 +882,75 @@
+
+
+
+
+ optional&
+ optional<T
(not a ref)>::operator= ( optional&& rhs
+ ) noexcept(
see below);
+
+
+
+
+
+
+ optional<T&> & optional<T&>::operator= ( optional<T&>&&
+ rhs )
+ ;
+
+-
+ Effect: Same as
optional<T&>::operator= ( optional<T&> const& rhs )
.
+
@@ -673,6 +1011,59 @@
+
+
+
+
+ template<U> optional&
+ optional<T
(not a ref)>::operator= ( optional<U>&&
+ rhs )
+ ;
+
+
@@ -768,7 +1159,7 @@
-
- Requirements:
*this
is initialized
+ Requires: *this
is initialized
-
Returns: A reference to the contained
@@ -870,7 +1261,7 @@
-
- Requirements:
*this
is initialized
+ Requires: *this
is initialized
-
Returns: The
@@ -956,7 +1347,7 @@
-
- Requirements:
*this
is initialized.
+ Requires: *this
is initialized.
-
Returns: A pointer to the contained value.
@@ -1008,16 +1399,13 @@
- bool optional<T>::operator!() ;
+ bool optional<T>::operator!() noexcept ;
-
Returns: If
*this
is uninitialized, true
;
else false
.
--
- Throws: Nothing.
-
-
Notes: This operator is provided for those
compilers which can't use the unspecified-bool-type operator
@@ -1291,7 +1679,7 @@
void swap
( optional<T>&
- x, optional<T>& y );
+ x, optional<T>& y ) ;
-
@@ -1308,19 +1696,21 @@
-
Throws: If both are initialized, whatever
swap(T&,T&)
- throws. If only one is initialized, whatever T::T ( T const& )
throws.
+ throws. If only one is initialized, whatever T::T ( T&&
+ )
throws.
-
Notes: If both are initialized,
swap(T&,T&)
is used unqualified but with std::swap
introduced in scope. If only one is initialized, T::~T()
and T::T(
- T const& )
- is called.
+ T&&
+ ) is called.
-
Exception Safety: If both are initialized,
this operation has the exception safety guarantees of
swap(T&,T&)
.
- If only one is initialized, it has the same basic guarantee as optional<T>::reset( T const& )
.
+ If only one is initialized, it has the same basic guarantee as optional<T>::operator= ( T&&
+ )
.
-
Example:
diff --git a/doc/html/boost_optional/optional_references.html b/doc/html/boost_optional/optional_references.html
index a603c1c..92770cf 100644
--- a/doc/html/boost_optional/optional_references.html
+++ b/doc/html/boost_optional/optional_references.html
@@ -68,6 +68,22 @@
than the reference itself.
+
+
+ Rvalue references and lvalue references to const have the ability in C++ to
+ extend the life time of a temporary they bind to. Optional references do not
+ have this capability, therefore to avoid surprising effects it is not possible
+ to initialize an optional references from a temporary. Optional rvalue references
+ are disabled altogether. Also, the initialization and assignment of an optional
+ reference to const from rvalue reference is disabled.
+
+const int& i = 1;
+optional<const int&> oi = 1;
+
|
diff --git a/doc/html/boost_optional/synopsis.html b/doc/html/boost_optional/synopsis.html
index 802fa02..8ce8e1f 100644
--- a/doc/html/boost_optional/synopsis.html
+++ b/doc/html/boost_optional/synopsis.html
@@ -37,19 +37,25 @@
- optional () ;
+ optional () noexcept ;
- optional ( none_t ) ;
+ optional ( none_t ) noexcept ;
optional ( T const& v ) ;
+ optional ( T&& v ) ;
+
optional ( bool condition, T const& v ) ;
optional ( optional const& rhs ) ;
+ optional ( optional&& rhs ) noexcept(see below) ;
+
template<class U> explicit optional ( optional<U> const& rhs ) ;
+ template<class U> explicit optional ( optional<U>&& rhs ) ;
+
template<class InPlaceFactory> explicit optional ( InPlaceFactory const& f ) ;
template<class TypedInPlaceFactory> explicit optional ( TypedInPlaceFactory const& f ) ;
@@ -58,10 +64,16 @@
optional& operator = ( T const& v ) ;
+ optional& operator = ( T&& v ) ;
+
optional& operator = ( optional const& rhs ) ;
+ optional& operator = ( optional&& rhs ) noexcept(see below) ;
+
template<class U> optional& operator = ( optional<U> const& rhs ) ;
+ template<class U> optional& operator = ( optional<U>&& rhs ) ;
+
template<class InPlaceFactory> optional& operator = ( InPlaceFactory const& f ) ;
template<class TypedInPlaceFactory> optional& operator = ( TypedInPlaceFactory const& f ) ;
@@ -83,7 +95,7 @@
explicit operator bool() const ;
- bool operator!() const ;
+ bool operator!() const noexcept ;
diff --git a/doc/html/index.html b/doc/html/index.html
index bdc5e5d..ba0c93f 100644
--- a/doc/html/index.html
+++ b/doc/html/index.html
@@ -163,7 +163,7 @@
-Last revised: April 26, 2014 at 08:58:33 GMT |
+Last revised: April 28, 2014 at 23:21:56 GMT |
|
diff --git a/doc/reference.qbk b/doc/reference.qbk
index d7cdfed..04b61aa 100644
--- a/doc/reference.qbk
+++ b/doc/reference.qbk
@@ -22,18 +22,24 @@
// (If T is of reference type, the parameters and results by reference are by value)
- optional () ; ``[link reference_optional_constructor __GO_TO__]``
+ optional () noexcept ; ``[link reference_optional_constructor __GO_TO__]``
- optional ( none_t ) ; ``[link reference_optional_constructor_none_t __GO_TO__]``
+ optional ( none_t ) noexcept ; ``[link reference_optional_constructor_none_t __GO_TO__]``
optional ( T const& v ) ; ``[link reference_optional_constructor_value __GO_TO__]``
+
+ 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__]``
+
+ optional ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_move_constructor_optional __GO_TO__]``
template explicit optional ( optional const& rhs ) ; ``[link reference_optional_constructor_other_optional __GO_TO__]``
+
+ template explicit optional ( optional&& rhs ) ; ``[link reference_optional_move_constructor_other_optional __GO_TO__]``
template explicit optional ( InPlaceFactory const& f ) ; ``[link reference_optional_constructor_factory __GO_TO__]``
@@ -42,10 +48,16 @@
optional& operator = ( none_t ) ; ``[/[link reference_optional_operator_equal_none_t __GO_TO__]]``
optional& operator = ( T const& v ) ; ``[link reference_optional_operator_equal_value __GO_TO__]``
+
+ optional& operator = ( T&& v ) ; ``[link reference_optional_operator_move_equal_value __GO_TO__]``
optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_optional __GO_TO__]``
+
+ optional& operator = ( optional&& rhs ) noexcept(``['see below]``) ; ``[link reference_optional_operator_move_equal_optional __GO_TO__]``
template optional& operator = ( optional const& rhs ) ; ``[link reference_optional_operator_equal_other_optional __GO_TO__]``
+
+ template optional& operator = ( optional&& rhs ) ; ``[link reference_optional_operator_move_equal_other_optional __GO_TO__]``
template optional& operator = ( InPlaceFactory const& f ) ; ``[link reference_optional_operator_equal_factory __GO_TO__]``
@@ -68,7 +80,7 @@
explicit operator bool() const ; ``[link reference_optional_operator_bool __GO_TO__]``
- bool operator!() const ; ``[link reference_optional_operator_not __GO_TO__]``
+ bool operator!() const noexcept ; ``[link reference_optional_operator_not __GO_TO__]``
// deprecated methods
@@ -151,12 +163,11 @@ __SPACE__
[#reference_optional_constructor]
-[: `optional::optional();`]
+[: `optional::optional() noexcept;`]
* [*Effect:] Default-Constructs an `optional`.
* [*Postconditions:] `*this` is [_uninitialized].
-* [*Throws:] Nothing.
-* Notes: T's default constructor [_is not] called.
+* [*Notes:] T's default constructor [_is not] called.
* [*Example:]
``
optional def ;
@@ -167,11 +178,10 @@ __SPACE__
[#reference_optional_constructor_none_t]
-[: `optional::optional( none_t );`]
+[: `optional::optional( none_t ) noexcept;`]
* [*Effect:] Constructs an `optional` uninitialized.
* [*Postconditions:] `*this` is [_uninitialized].
-* [*Throws:] Nothing.
* [*Notes:] `T`'s default constructor [_is not] called. The expression
`boost::none` denotes an instance of `boost::none_t` that can be used as
the parameter.
@@ -188,8 +198,9 @@ __SPACE__
[: `optional::optional( T const& v )`]
+* [*Requires:] `is_copy_constructible::value` is `true`.
* [*Effect:] Directly-Constructs an `optional`.
-* [*Postconditions:] `*this` is [_initialized] and its value is a['copy]
+* [*Postconditions:] `*this` is [_initialized] and its value is a ['copy]
of `v`.
* [*Throws:] Whatever `T::T( T const& )` throws.
* [*Notes: ] `T::T( T const& )` is called.
@@ -220,6 +231,33 @@ assert ( *opt == v ) ;
assert (*opt == v);
``
+__SPACE__
+
+[#reference_optional_constructor_move_value]
+
+[: `optional::optional( T&& v )`]
+
+* [*Requires:] `is_move_constructible::value` is `true`.
+* [*Effect:] Directly-Move-Constructs an `optional`.
+* [*Postconditions:] `*this` is [_initialized] and its value is move-constructed from `v`.
+* [*Throws:] Whatever `T::T( T&& )` throws.
+* [*Notes: ] `T::T( T&& )` is called.
+* [*Exception Safety:] Exceptions can only be thrown during
+`T::T( T&& );` in that case, the state of `v` is determined by exception safety guarantees for `T::T(T&&)`.
+* [*Example:]
+``
+T v1, v2;
+optional opt(std::move(v1));
+assert ( *opt == v2 ) ;
+``
+
+__SPACE__
+
+[: `optional::optional( T&& ref ) = delete`]
+
+* [*Notes:] This constructor is deleted
+
+
__SPACE__
[#reference_optional_constructor_bool_value]
@@ -243,6 +281,7 @@ __SPACE__
[: `optional::optional( optional const& rhs );`]
+* [*Requires:] `is_copy_constructible::value` is `true`.
* [*Effect:] Copy-Constructs an `optional`.
* [*Postconditions:] If rhs is initialized, `*this` is initialized and
its value is a ['copy] of the value of `rhs`; else `*this` is uninitialized.
@@ -299,6 +338,70 @@ assert ( *init2 == 3 ) ;
__SPACE__
+[#reference_optional_move_constructor_optional]
+
+[: `optional::optional( optional&& rhs ) noexcept(`['see below]`);`]
+
+* [*Requires:] `is_move_constructible::value` is `true`.
+* [*Effect:] Move-constructs an `optional`.
+* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and
+its value is move constructed from `rhs`; else `*this` is uninitialized.
+* [*Throws:] Whatever `T::T( T&& )` throws.
+* [*Notes:] If `rhs` is initialized, `T::T( T && )` is called. The expression inside `noexcept` is equivalent to `is_nothrow_move_constructible::value`.
+* [*Exception Safety:] Exceptions can only be thrown during
+`T::T( T&& );` in that case, `rhs` remains initialized and the value of `*rhs` is determined by exception safety of `T::T(T&&)`.
+* [*Example:]
+``
+optional> uninit ;
+assert (!uninit);
+
+optional> uinit2 ( std::move(uninit) ) ;
+assert ( uninit2 == uninit );
+
+optional> init( std::uniqye_ptr(new T(2)) );
+assert ( **init == T(2) ) ;
+
+optional> init2 ( std::move(init) ) ;
+assert ( init );
+assert ( *init == nullptr );
+assert ( init2 );
+assert ( **init2 == T(2) ) ;
+``
+
+__SPACE__
+
+[: `optional::optional( optional && rhs );`]
+
+* [*Effect:] Move-Constructs an `optional`.
+* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and its
+value is another reference to the same object referenced by `*rhs`; else
+`*this` is uninitialized.
+* [*Throws:] Nothing.
+* [*Notes:] If `rhs` is initialized, both `*this` and `*rhs` will reefer to the
+same object (they alias).
+* [*Example:]
+``
+optional&> uninit ;
+assert (!uninit);
+
+optional&> uinit2 ( std::move(uninit) ) ;
+assert ( uninit2 == uninit );
+
+std::unique_ptr v(new T(2)) ;
+optional&> init(v);
+assert ( *init == v ) ;
+
+optional&> init2 ( std::move(init) ) ;
+assert ( *init2 == v ) ;
+
+*v = 3 ;
+
+assert ( **init == 3 ) ;
+assert ( **init2 == 3 ) ;
+``
+
+__SPACE__
+
[#reference_optional_constructor_other_optional]
[: `template explicit optional::optional( optional const& rhs );`]
@@ -323,6 +426,30 @@ assert( *y == 123 ) ;
__SPACE__
+[#reference_optional_move_constructor_other_optional]
+
+[: `template explicit optional::optional( optional&& rhs );`]
+
+* [*Effect:] Move-constructs an `optional`.
+* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and its
+value is move constructed from `*rhs`; else `*this` is
+uninitialized.
+* [*Throws:] Whatever `T::T( U&& )` throws.
+* [*Notes: ] `T::T( U&& )` is called if `rhs` is initialized, which requires a
+valid conversion from `U` to `T`.
+* [*Exception Safety:] Exceptions can only be thrown during `T::T( U&& );`
+in that case, `rhs` remains initialized and the value of `*rhs` is determined by exception safety guarantee of `T::T( U&& )`.
+* [*Example:]
+``
+optional x(123.4);
+assert ( *x == 123.4 ) ;
+
+optional y(std::move(x)) ;
+assert( *y == 123 ) ;
+``
+
+__SPACE__
+
[#reference_optional_constructor_factory]
[: `template explicit optional::optional( InPlaceFactory const& f );`]
@@ -408,6 +535,42 @@ c = 4 ;
assert ( *opt == 4 ) ;
``
+__SPACE__
+
+[#reference_optional_operator_move_equal_value]
+
+[: `optional& optional::operator= ( T&& rhs ) ;`]
+
+* [*Effect:] Moves the value `rhs` to an `optional`.
+* [*Postconditions: ] `*this` is initialized and its value is moved from `rhs`.
+* [*Throws:] Whatever `T::operator=( T&& )` or `T::T(T &&)` throws.
+* [*Notes:] If `*this` was initialized, `T`'s move-assignment operator is used,
+otherwise, its move-constructor is used.
+* [*Exception Safety:] In the event of an exception, the initialization
+state of `*this` is unchanged and its value unspecified as far as `optional`
+is concerned (it is up to `T`'s `operator=()`). If `*this` is initially
+uninitialized and `T`'s ['move constructor] fails, `*this` is left properly
+uninitialized.
+* [*Example:]
+``
+T x;
+optional def ;
+optional opt(x) ;
+
+T y1, y2, yR;
+def = std::move(y1) ;
+assert ( *def == yR ) ;
+opt = std::move(y2) ;
+assert ( *opt == yR ) ;
+``
+
+__SPACE__
+
+[: `optional& optional::operator= ( T&& rhs ) = delete;`]
+
+* [*Notes:] This assignment operator is deleted.
+
+
__SPACE__
[#reference_optional_operator_equal_optional]
@@ -471,6 +634,42 @@ assert ( *ora == 4 ) ;
__SPACE__
+[#reference_optional_operator_move_equal_optional]
+
+[: `optional& optional::operator= ( optional&& rhs ) noexcept(`['see below]`);`]
+
+* [*Effect:] Move-assigns another `optional` to an `optional`.
+* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and
+its value is moved from `*rhs`, `rhs` remains initialized; else `*this` is uninitialized.
+* [*Throws:] Whatever `T::operator( T&& )` or `T::T( T && )` throws.
+* [*Notes:] If both `*this` and `rhs` are initially initialized, `T`'s
+['move assignment operator] is used. If `*this` is initially initialized but `rhs` is
+uninitialized, `T`'s [destructor] is called. If `*this` is initially uninitialized
+but `rhs` is initialized, `T`'s ['move constructor] is called. The expression inside `noexcept` is equivalent to `is_nothrow_move_constructible::value && is_nothrow_move_assignable::value`.
+* [*Exception Safety:] In the event of an exception, the initialization state of
+`*this` is unchanged and its value unspecified as far as optional is concerned
+(it is up to `T`'s `operator=()`). If `*this` is initially uninitialized and
+`T`'s ['move constructor] fails, `*this` is left properly uninitialized.
+* [*Example:]
+``
+optional opt(T(2)) ;
+optional def ;
+
+opt = def ;
+assert ( def ) ;
+assert ( opt ) ;
+assert ( *opt == T(2) ) ;
+``
+
+__SPACE__
+
+[: `optional & optional::operator= ( optional&& rhs ) ;`]
+
+* [*Effect:] Same as `optional::operator= ( optional const& rhs )`.
+
+__SPACE__
+
+
[#reference_optional_operator_equal_other_optional]
[: `template optional& optional::operator= ( optional const& rhs ) ;`]
@@ -502,6 +701,37 @@ assert ( *opt1 == static_cast(v) ) ;
__SPACE__
+[#reference_optional_operator_move_equal_other_optional]
+
+[: `template optional& optional::operator= ( optional&& rhs ) ;`]
+
+* [*Effect:] Move-assigns another convertible optional to an optional.
+* [*Postconditions:] If `rhs` is initialized, `*this` is initialized and
+its value is moved from the value of `rhs`; else
+`*this` is uninitialized.
+* [*Throws:] Whatever `T::operator=( U&& )` or `T::T( U&& )` throws.
+* [*Notes:] If both `*this` and `rhs` are initially initialized, `T`'s
+[' assignment operator] (from `U&&`) is used. If `*this` is initially initialized
+but `rhs` is uninitialized, `T`'s ['destructor] is called. If `*this` is
+initially uninitialized but `rhs` is initialized, `T`'s ['converting constructor]
+(from `U&&`) is called.
+* [*Exception Safety:] In the event of an exception, the initialization state
+of `*this` is unchanged and its value unspecified as far as optional is
+concerned (it is up to `T`'s `operator=()`). If `*this` is initially
+uninitialized and `T`'s converting constructor fails, `*this` is left properly
+uninitialized.
+* [*Example:]
+``
+T v;
+optional opt0(v);
+optional opt1;
+
+opt1 = std::move(opt0) ;
+assert ( *opt1 == static_cast(v) ) ;
+``
+
+__SPACE__
+
[#reference_optional_operator_equal_factory]
[: `template optional& optional::operator=( InPlaceFactory const& f );`]
@@ -543,7 +773,7 @@ __SPACE__
[: `inline T const& get ( optional const& ) ;`]
[: `inline T& get ( optional &) ;`]
-* [*Requirements:] `*this` is initialized
+* [*Requires:] `*this` is initialized
* [*Returns:] A reference to the contained value
* [*Throws:] Nothing.
* [*Notes:] The requirement is asserted via `BOOST_ASSERT()`.
@@ -593,7 +823,7 @@ __SPACE__
[: `inline T const& get ( optional const& ) ;`]
[: `inline T& get ( optional &) ;`]
-* [*Requirements: ] `*this` is initialized
+* [*Requires: ] `*this` is initialized
* [*Returns:] [_The] reference contained.
* [*Throws:] Nothing.
* [*Notes:] The requirement is asserted via `BOOST_ASSERT()`.
@@ -641,7 +871,7 @@ __SPACE__
[: `T const* optional::operator ->() const ;`]
[: `T* optional::operator ->() ;`]
-* [*Requirements: ] `*this` is initialized.
+* [*Requires: ] `*this` is initialized.
* [*Returns:] A pointer to the contained value.
* [*Throws:] Nothing.
* [*Notes:] The requirement is asserted via `BOOST_ASSERT()`.
@@ -675,10 +905,9 @@ __SPACE__
[#reference_optional_operator_not]
-[: `bool optional::operator!() ;`]
+[: `bool optional::operator!() noexcept ;`]
* [*Returns:] If `*this` is uninitialized, `true`; else `false`.
-* [*Throws:] Nothing.
* [*Notes:] This operator is provided for those compilers which can't
use the ['unspecified-bool-type operator] in certain boolean contexts.
* [*Example:]
@@ -852,21 +1081,21 @@ __SPACE__
[#reference_swap_optional_optional]
-[: `void swap ( optional& x, optional& y );`]
+[: `void swap ( optional& x, optional& y ) ;`]
* [*Effect:] If both `x` and `y` are initialized, calls `swap(*x,*y)`
using `std::swap`. If only one is initialized, say `x`, calls:
`y.reset(*x); x.reset();` If none is initialized, does nothing.
* [*Postconditions:] The states of `x` and `y` interchanged.
* [*Throws:] If both are initialized, whatever `swap(T&,T&)` throws. If only
-one is initialized, whatever `T::T ( T const& )` throws.
+one is initialized, whatever `T::T ( T&& )` throws.
* [*Notes:] If both are initialized, `swap(T&,T&)` is used unqualified but
with `std::swap` introduced in scope.
-If only one is initialized, `T::~T()` and `T::T( T const& )` is called.
+If only one is initialized, `T::~T()` and `T::T( T&& )` is called.
* [*Exception Safety:] If both are initialized, this operation has the
exception safety guarantees of `swap(T&,T&)`.
If only one is initialized, it has the same basic guarantee as
-`optional::reset( T const& )`.
+`optional::operator= ( T&& )`.
* [*Example:]
``
T x(12);
diff --git a/doc/special_cases.qbk b/doc/special_cases.qbk
index 681e517..0f6f22b 100644
--- a/doc/special_cases.qbk
+++ b/doc/special_cases.qbk
@@ -21,6 +21,13 @@ will nonetheless reefer to the same object.
* Value-access will actually provide access to the referenced object
rather than the reference itself.
+[heading Rvalue references]
+
+Rvalue references and lvalue references to const have the ability in C++ to extend the life time of a temporary they bind to. Optional references do not have this capability, therefore to avoid surprising effects it is not possible to initialize an optional references from a temporary. Optional rvalue references are disabled altogether. Also, the initialization and assignment of an optional reference to const from rvalue reference is disabled.
+
+ const int& i = 1; // legal
+ optional oi = 1; // illegal
+
[endsect]
[section Rebinding semantics for assignment of optional references]
diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp
index d87b6fa..c8752af 100644
--- a/include/boost/optional/optional.hpp
+++ b/include/boost/optional/optional.hpp
@@ -21,22 +21,34 @@
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
+#include
+#include
+#include
+#include
#include
+#include
+#include
#include
#include
#include
#include
+#include
#include
-#include
#include
#include
-#include
+#include
#include
+#include
+#include
+
+
#include
@@ -132,22 +144,39 @@ struct types_when_isnt_ref
{
typedef T const& reference_const_type ;
typedef T & reference_type ;
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ typedef T && rval_reference_type ;
+ static rval_reference_type move(reference_type r) { return boost::move(r); }
+#endif
typedef T const* pointer_const_type ;
typedef T * pointer_type ;
typedef T const& argument_type ;
} ;
+
template
struct types_when_is_ref
{
typedef BOOST_DEDUCED_TYPENAME remove_reference::type raw_type ;
- typedef raw_type& reference_const_type ;
- typedef raw_type& reference_type ;
- typedef raw_type* pointer_const_type ;
- typedef raw_type* pointer_type ;
- typedef raw_type& argument_type ;
+ typedef raw_type& reference_const_type ;
+ typedef raw_type& reference_type ;
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ typedef raw_type&& rval_reference_type ;
+ static reference_type move(reference_type r) { return r; }
+#endif
+ typedef raw_type* pointer_const_type ;
+ typedef raw_type* pointer_type ;
+ typedef raw_type& argument_type ;
} ;
+template
+void prevent_binding_rvalue_ref_to_optional_lvalue_ref()
+{
+ BOOST_STATIC_ASSERT_MSG(
+ !boost::is_lvalue_reference::value || !boost::is_rvalue_reference::value,
+ "binding rvalue references to optional lvalue references is disallowed");
+}
+
struct optional_tag {} ;
template
@@ -183,6 +212,9 @@ class optional_base : public optional_tag
protected:
typedef BOOST_DEDUCED_TYPENAME types::reference_type reference_type ;
typedef BOOST_DEDUCED_TYPENAME types::reference_const_type reference_const_type ;
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ typedef BOOST_DEDUCED_TYPENAME types::rval_reference_type rval_reference_type ;
+#endif
typedef BOOST_DEDUCED_TYPENAME types::pointer_type pointer_type ;
typedef BOOST_DEDUCED_TYPENAME types::pointer_const_type pointer_const_type ;
typedef BOOST_DEDUCED_TYPENAME types::argument_type argument_type ;
@@ -208,6 +240,17 @@ class optional_base : public optional_tag
construct(val);
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // move-construct an optional initialized from an rvalue-ref to 'val'.
+ // Can throw if T::T(T&&) does
+ optional_base ( rval_reference_type val )
+ :
+ m_initialized(false)
+ {
+ construct( boost::move(val) );
+ }
+#endif
+
// Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional.
// Can throw if T::T(T const&) does
optional_base ( bool cond, argument_type val )
@@ -228,7 +271,29 @@ class optional_base : public optional_tag
construct(rhs.get_impl());
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Creates a deep move of another optional
+ // Can throw if T::T(T&&) does
+ optional_base ( optional_base&& rhs )
+ :
+ m_initialized(false)
+ {
+ if ( rhs.is_initialized() )
+ construct( boost::move(rhs.get_impl()) );
+ }
+#endif
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+ template
+ explicit optional_base ( Expr&& expr, PtrExpr const* tag )
+ :
+ m_initialized(false)
+ {
+ construct(boost::forward(expr),tag);
+ }
+
+#else
// This is used for both converting and in-place constructions.
// Derived classes use the 'tag' to select the appropriate
// implementation (the correct 'construct()' overload)
@@ -240,6 +305,7 @@ class optional_base : public optional_tag
construct(expr,tag);
}
+#endif
// No-throw (assuming T::~T() doesn't)
@@ -260,6 +326,24 @@ class optional_base : public optional_tag
construct(rhs.get_impl());
}
}
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Assigns from another optional (deep-moves the rhs value)
+ void assign ( optional_base&& rhs )
+ {
+ if (is_initialized())
+ {
+ if ( rhs.is_initialized() )
+ assign_value(boost::move(rhs.get_impl()), is_reference_predicate() );
+ else destroy();
+ }
+ else
+ {
+ if ( rhs.is_initialized() )
+ construct(boost::move(rhs.get_impl()));
+ }
+ }
+#endif
// Assigns from another _convertible_ optional (deep-copies the rhs value)
template
@@ -278,6 +362,26 @@ class optional_base : public optional_tag
}
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // move-assigns from another _convertible_ optional (deep-moves from the rhs value)
+ template
+ void assign ( optional&& rhs )
+ {
+ typedef BOOST_DEDUCED_TYPENAME optional::rval_reference_type ref_type;
+ if (is_initialized())
+ {
+ if ( rhs.is_initialized() )
+ assign_value(static_cast(rhs.get()), is_reference_predicate() );
+ else destroy();
+ }
+ else
+ {
+ if ( rhs.is_initialized() )
+ construct(static_cast(rhs.get()));
+ }
+ }
+#endif
+
// Assigns from a T (deep-copies the rhs value)
void assign ( argument_type val )
{
@@ -285,19 +389,41 @@ class optional_base : public optional_tag
assign_value(val, is_reference_predicate() );
else construct(val);
}
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Assigns from a T (deep-moves the rhs value)
+ void assign ( rval_reference_type val )
+ {
+ if (is_initialized())
+ assign_value( boost::move(val), is_reference_predicate() );
+ else construct( boost::move(val) );
+ }
+#endif
// Assigns from "none", destroying the current value, if any, leaving this UNINITIALIZED
// No-throw (assuming T::~T() doesn't)
void assign ( none_t ) { destroy(); }
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ template
+ void assign_expr ( Expr&& expr, ExprPtr const* tag )
+ {
+ if (is_initialized())
+ assign_expr_to_initialized(boost::forward(expr),tag);
+ else construct(boost::forward(expr),tag);
+ }
+#else
template
void assign_expr ( Expr const& expr, Expr const* tag )
- {
- if (is_initialized())
- assign_expr_to_initialized(expr,tag);
- else construct(expr,tag);
- }
+ {
+ if (is_initialized())
+ assign_expr_to_initialized(expr,tag);
+ else construct(expr,tag);
+ }
+#endif
+
#endif
public :
@@ -324,8 +450,51 @@ class optional_base : public optional_tag
new (m_storage.address()) internal_type(val) ;
m_initialized = true ;
}
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ void construct ( rval_reference_type val )
+ {
+ new (m_storage.address()) internal_type( types::move(val) ) ;
+ m_initialized = true ;
+ }
+#endif
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Constructs in-place using the given factory
+ template
+ void construct ( Expr&& factory, in_place_factory_base const* )
+ {
+ BOOST_STATIC_ASSERT ( ::boost::mpl::not_::value ) ;
+ boost_optional_detail::construct(factory, m_storage.address());
+ m_initialized = true ;
+ }
+
+ // Constructs in-place using the given typed factory
+ template
+ void construct ( Expr&& factory, typed_in_place_factory_base const* )
+ {
+ BOOST_STATIC_ASSERT ( ::boost::mpl::not_::value ) ;
+ factory.apply(m_storage.address()) ;
+ m_initialized = true ;
+ }
+
+ template
+ void assign_expr_to_initialized ( Expr&& factory, in_place_factory_base const* tag )
+ {
+ destroy();
+ construct(factory,tag);
+ }
+
+ // Constructs in-place using the given typed factory
+ template
+ void assign_expr_to_initialized ( Expr&& factory, typed_in_place_factory_base const* tag )
+ {
+ destroy();
+ construct(factory,tag);
+ }
+#else
// Constructs in-place using the given factory
template
void construct ( Expr const& factory, in_place_factory_base const* )
@@ -360,7 +529,31 @@ class optional_base : public optional_tag
}
#endif
- // Constructs using any expression implicitely convertible to the single argument
+#endif
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Constructs using any expression implicitly convertible to the single argument
+ // of a one-argument T constructor.
+ // Converting constructions of optional from optional uses this function with
+ // 'Expr' being of type 'U' and relying on a converting constructor of T from U.
+ template
+ void construct ( Expr&& expr, void const* )
+ {
+ new (m_storage.address()) internal_type(boost::forward(expr)) ;
+ m_initialized = true ;
+ }
+
+ // Assigns using a form any expression implicitly convertible to the single argument
+ // of a T's assignment operator.
+ // Converting assignments of optional from optional uses this function with
+ // 'Expr' being of type 'U' and relying on a converting assignment of T from U.
+ template
+ void assign_expr_to_initialized ( Expr&& expr, void const* )
+ {
+ assign_value(boost::forward(expr), is_reference_predicate());
+ }
+#else
+ // Constructs using any expression implicitly convertible to the single argument
// of a one-argument T constructor.
// Converting constructions of optional from optional uses this function with
// 'Expr' being of type 'U' and relying on a converting constructor of T from U.
@@ -371,7 +564,7 @@ class optional_base : public optional_tag
m_initialized = true ;
}
- // Assigns using a form any expression implicitely convertible to the single argument
+ // Assigns using a form any expression implicitly convertible to the single argument
// of a T's assignment operator.
// Converting assignments of optional from optional uses this function with
// 'Expr' being of type 'U' and relying on a converting assignment of T from U.
@@ -381,6 +574,8 @@ class optional_base : public optional_tag
assign_value(expr, is_reference_predicate());
}
+#endif
+
#ifdef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
// BCB5.64 (and probably lower versions) workaround.
// The in-place factories are supported by means of catch-all constructors
@@ -394,6 +589,20 @@ class optional_base : public optional_tag
// For VC<=70 compilers this workaround dosen't work becasue the comnpiler issues and error
// instead of choosing the wrong overload
//
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Notice that 'Expr' will be optional or optional (but not optional_base<..>)
+ template
+ void construct ( Expr&& expr, optional_tag const* )
+ {
+ if ( expr.is_initialized() )
+ {
+ // An exception can be thrown here.
+ // It it happens, THIS will be left uninitialized.
+ new (m_storage.address()) internal_type(types::move(expr.get())) ;
+ m_initialized = true ;
+ }
+ }
+#else
// Notice that 'Expr' will be optional or optional (but not optional_base<..>)
template
void construct ( Expr const& expr, optional_tag const* )
@@ -407,9 +616,14 @@ class optional_base : public optional_tag
}
}
#endif
+#endif // defined BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
void assign_value ( argument_type val, is_not_reference_tag ) { get_impl() = val; }
void assign_value ( argument_type val, is_reference_tag ) { construct(val); }
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ void assign_value ( rval_reference_type val, is_not_reference_tag ) { get_impl() = static_cast(val); }
+ void assign_value ( rval_reference_type val, is_reference_tag ) { construct( static_cast(val) ); }
+#endif
void destroy()
{
@@ -483,22 +697,32 @@ class optional : public optional_detail::optional_base
typedef BOOST_DEDUCED_TYPENAME base::value_type value_type ;
typedef BOOST_DEDUCED_TYPENAME base::reference_type reference_type ;
typedef BOOST_DEDUCED_TYPENAME base::reference_const_type reference_const_type ;
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ typedef BOOST_DEDUCED_TYPENAME base::rval_reference_type rval_reference_type ;
+#endif
typedef BOOST_DEDUCED_TYPENAME base::pointer_type pointer_type ;
typedef BOOST_DEDUCED_TYPENAME base::pointer_const_type pointer_const_type ;
typedef BOOST_DEDUCED_TYPENAME base::argument_type argument_type ;
// Creates an optional uninitialized.
// No-throw
- optional() : base() {}
+ optional() BOOST_NOEXCEPT : base() {}
// Creates an optional uninitialized.
// No-throw
- optional( none_t none_ ) : base(none_) {}
+ optional( none_t none_ ) BOOST_NOEXCEPT : base(none_) {}
// Creates an optional initialized with 'val'.
// Can throw if T::T(T const&) does
optional ( argument_type val ) : base(val) {}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Creates an optional initialized with 'move(val)'.
+ // Can throw if T::T(T &&) does
+ optional ( rval_reference_type val ) : base( boost::forward(val) )
+ {optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref();}
+#endif
+
// Creates an optional initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional.
// Can throw if T::T(T const&) does
optional ( bool cond, argument_type val ) : base(cond,val) {}
@@ -516,40 +740,94 @@ class optional : public optional_detail::optional_base
if ( rhs.is_initialized() )
this->construct(rhs.get());
}
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Creates a deep move of another convertible optional
+ // Requires a valid conversion from U to T.
+ // Can throw if T::T(U&&) does
+ template
+ explicit optional ( optional && rhs )
+ :
+ base()
+ {
+ if ( rhs.is_initialized() )
+ this->construct( boost::move(rhs.get()) );
+ }
+#endif
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
// Creates an optional with an expression which can be either
// (a) An instance of InPlaceFactory (i.e. in_place(a,b,...,n);
// (b) An instance of TypedInPlaceFactory ( i.e. in_place(a,b,...,n);
- // (c) Any expression implicitely convertible to the single type
+ // (c) Any expression implicitly convertible to the single type
// of a one-argument T's constructor.
// (d*) Weak compilers (BCB) might also resolved Expr as optional and optional
// even though explicit overloads are present for these.
// Depending on the above some T ctor is called.
- // Can throw is the resolved T ctor throws.
+ // Can throw if the resolved T ctor throws.
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+
+ template
+ explicit optional ( Expr&& expr,
+ BOOST_DEDUCED_TYPENAME boost::disable_if_c<
+ (boost::is_base_of::type>::value) ||
+ boost::is_same::type, none_t>::value >::type* = 0
+ )
+ : base(boost::forward(expr),boost::addressof(expr))
+ {optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref();}
+
+#else
template
explicit optional ( Expr const& expr ) : base(expr,boost::addressof(expr)) {}
-#endif
+#endif // !defined BOOST_NO_CXX11_RVALUE_REFERENCES
+#endif // !defined BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
// Creates a deep copy of another optional
// Can throw if T::T(T const&) does
optional ( optional const& rhs ) : base( static_cast(rhs) ) {}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Creates a deep move of another optional
+ // Can throw if T::T(T&&) does
+ optional ( optional && rhs )
+ BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value)
+ : base( boost::move(rhs) )
+ {}
+
+#endif
// No-throw (assuming T::~T() doesn't)
~optional() {}
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION)
// Assigns from an expression. See corresponding constructor.
// Basic Guarantee: If the resolved T ctor throws, this is left UNINITIALIZED
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+ template
+ BOOST_DEDUCED_TYPENAME boost::disable_if_c<
+ boost::is_base_of::type>::value ||
+ boost::is_same::type, none_t>::value,
+ optional&
+ >::type
+ operator= ( Expr&& expr )
+ {
+ optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref();
+ this->assign_expr(boost::forward(expr),boost::addressof(expr));
+ return *this ;
+ }
+
+#else
template
optional& operator= ( Expr const& expr )
{
this->assign_expr(expr,boost::addressof(expr));
return *this ;
}
-#endif
+#endif // !defined BOOST_NO_CXX11_RVALUE_REFERENCES
+#endif // !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) && !defined(BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION)
- // Assigns from another convertible optional (converts && deep-copies the rhs value)
+ // Copy-assigns from another convertible optional (converts && deep-copies the rhs value)
// Requires a valid conversion from U to T.
// Basic Guarantee: If T::T( U const& ) throws, this is left UNINITIALIZED
template
@@ -558,6 +836,18 @@ class optional : public optional_detail::optional_base
this->assign(rhs);
return *this ;
}
+
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Move-assigns from another convertible optional (converts && deep-moves the rhs value)
+ // Requires a valid conversion from U to T.
+ // Basic Guarantee: If T::T( U && ) throws, this is left UNINITIALIZED
+ template
+ optional& operator= ( optional && rhs )
+ {
+ this->assign(boost::move(rhs));
+ return *this ;
+ }
+#endif
// Assigns from another optional (deep-copies the rhs value)
// Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED
@@ -568,6 +858,16 @@ class optional : public optional_detail::optional_base
return *this ;
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Assigns from another optional (deep-moves the rhs value)
+ optional& operator= ( optional && rhs )
+ BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && ::boost::is_nothrow_move_assignable::value)
+ {
+ this->assign( static_cast(rhs) ) ;
+ return *this ;
+ }
+#endif
+
// 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 )
@@ -576,6 +876,15 @@ class optional : public optional_detail::optional_base
return *this ;
}
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Assigns from a T (deep-moves the rhs value)
+ optional& operator= ( rval_reference_type val )
+ {
+ this->assign( boost::move(val) ) ;
+ return *this ;
+ }
+#endif
+
// Assigns from a "none"
// Which destroys the current value, if any, leaving this UNINITIALIZED
// No-throw (assuming T::~T() doesn't)
@@ -586,10 +895,10 @@ class optional : public optional_detail::optional_base
}
void swap( optional & arg )
+ BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && ::boost::is_nothrow_move_assignable::value)
{
// allow for Koenig lookup
- using boost::swap;
- swap(*this, arg);
+ boost::swap(*this, arg);
}
@@ -615,11 +924,19 @@ class optional : public optional_detail::optional_base
reference_const_type operator *() const { return this->get() ; }
reference_type operator *() { return this->get() ; }
- bool operator!() const { return !this->is_initialized() ; }
+ bool operator!() const BOOST_NOEXCEPT { return !this->is_initialized() ; }
BOOST_EXPLICIT_OPERATOR_BOOL()
} ;
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+template
+class optional
+{
+ BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, "Optional rvalue references are illegal.");
+} ;
+#endif
+
// Returns optional(v)
template
inline
@@ -919,6 +1236,37 @@ struct swap_selector
}
};
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+template<>
+struct swap_selector
+{
+ template
+ static void optional_swap ( optional& x, optional& y )
+ //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
+ {
+ if(x)
+ {
+ if (y)
+ {
+ boost::swap(*x, *y);
+ }
+ else
+ {
+ y = boost::move(*x);
+ x = boost::none;
+ }
+ }
+ else
+ {
+ if (y)
+ {
+ x = boost::move(*y);
+ y = boost::none;
+ }
+ }
+ }
+};
+#else
template<>
struct swap_selector
{
@@ -945,6 +1293,7 @@ struct swap_selector
}
}
};
+#endif // !defined BOOST_NO_CXX11_RVALUE_REFERENCES
} // namespace optional_detail
@@ -952,6 +1301,7 @@ template
struct optional_swap_should_use_default_constructor : has_nothrow_default_constructor {} ;
template inline void swap ( optional& x, optional& y )
+ //BOOST_NOEXCEPT_IF(::boost::is_nothrow_move_constructible::value && BOOST_NOEXCEPT_EXPR(boost::swap(*x, *y)))
{
optional_detail::swap_selector::value>::optional_swap(x, y);
}
diff --git a/include/boost/optional/optional_fwd.hpp b/include/boost/optional/optional_fwd.hpp
index 388cc1c..29cee49 100644
--- a/include/boost/optional/optional_fwd.hpp
+++ b/include/boost/optional/optional_fwd.hpp
@@ -11,15 +11,18 @@
//
// Revisions:
// 10 May 2008 (added swap related forward declaration) Niels Dekker
-//
+// 17 Apr 2014 (added noexcept) Andrzej Krzemienski
+//
#ifndef BOOST_OPTIONAL_OPTIONAL_FWD_FLC_19NOV2002_HPP
#define BOOST_OPTIONAL_OPTIONAL_FWD_FLC_19NOV2002_HPP
+#include
+
namespace boost {
template class optional ;
-template void swap ( optional& , optional& ) ;
+template void swap ( optional& , optional