diff -purN orig/boost/optional/optional.hpp boost_1_48_0/boost/optional/optional.hpp --- orig/boost/optional/optional.hpp 2011-11-28 16:51:33.112345763 -0500 +++ boost_1_48_0/boost/optional/optional.hpp 2011-11-28 16:51:34.633345670 -0500 @@ -152,6 +152,9 @@ struct types_when_isnt_ref { typedef T const& reference_const_type ; typedef T & reference_type ; +#ifdef BOOST_HAS_RVALUE_REFS + typedef T && rreference_type ; +#endif typedef T const* pointer_const_type ; typedef T * pointer_type ; typedef T const& argument_type ; @@ -163,6 +166,9 @@ struct types_when_is_ref typedef raw_type& reference_const_type ; typedef raw_type& reference_type ; +#ifdef BOOST_HAS_RVALUE_REFS + typedef raw_type&& rreference_type ; +#endif typedef raw_type* pointer_const_type ; typedef raw_type* pointer_type ; typedef raw_type& argument_type ; @@ -205,6 +211,9 @@ class optional_base : public optional_ta typedef BOOST_DEDUCED_TYPENAME types::reference_type reference_type ; typedef BOOST_DEDUCED_TYPENAME types::reference_const_type reference_const_type ; +#ifdef BOOST_HAS_RVALUE_REFS + typedef BOOST_DEDUCED_TYPENAME types::rreference_type rreference_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 ; @@ -240,6 +249,27 @@ class optional_base : public optional_ta construct(val); } +#ifdef BOOST_HAS_RVALUE_REFS + // Creates an optional move-constructed from 'val' + // Can throw if T::T(T &&) does + optional_base ( rreference_type val ) + : + m_initialized(false) + { + construct(std::forward(val)); + } + + // Creates an optional move-constructed from 'val' IFF cond is true, otherwise creates an uninitialzed optional. + // Can throw if T::T(T &&) does + optional_base ( bool cond, rreference_type val ) + : + m_initialized(false) + { + if ( cond ) + construct(std::forward(val)); + } +#endif + // Creates a deep copy of another optional // Can throw if T::T(T const&) does optional_base ( optional_base const& rhs ) @@ -308,6 +338,16 @@ class optional_base : public optional_ta else construct(val); } +#ifdef BOOST_HAS_RVALUE_REFS + // Assigns from a T (moves the rhs value) + void assign ( rreference_type val ) + { + if (is_initialized()) + assign_value(std::forward(val), is_reference_predicate() ); + else construct(std::forward(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(); } @@ -347,6 +387,14 @@ class optional_base : public optional_ta m_initialized = true ; } +#ifdef BOOST_HAS_RVALUE_REFS + void construct ( rreference_type val ) + { + new (m_storage.address()) internal_type(std::forward(val)) ; + m_initialized = true ; + } +#endif + #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT // Constructs in-place using the given factory template @@ -432,6 +480,10 @@ class optional_base : public optional_ta void assign_value ( argument_type val, is_not_reference_tag ) { get_impl() = val; } void assign_value ( argument_type val, is_reference_tag ) { construct(val); } +#ifdef BOOST_HAS_RVALUE_REFS + void assign_value ( rreference_type val, is_not_reference_tag ) { get_impl() = std::forward(val); } + void assign_value ( rreference_type val, is_reference_tag ) { construct(std::forward(val)); } +#endif void destroy() { @@ -509,6 +561,9 @@ class optional : public optional_detail: 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 ; +#ifdef BOOST_HAS_RVALUE_REFS + typedef BOOST_DEDUCED_TYPENAME base::rreference_type rreference_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 ; @@ -529,6 +584,16 @@ class optional : public optional_detail: // Can throw if T::T(T const&) does optional ( bool cond, argument_type val ) : base(cond,val) {} +#ifdef BOOST_HAS_RVALUE_REFS + // Creates an optional moved from 'val'. + // Can throw if T::T(T &&) does + optional ( rreference_type val ) : base(std::forward(val)) {} + + // Creates an optional moved from 'val' IFF cond is true, otherwise creates an uninitialized optional. + // Can throw if T::T(T &&) does + optional ( bool cond, rreference_type val ) : base(cond,std::forward(val)) {} +#endif + #ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR // NOTE: MSVC needs templated versions first @@ -607,6 +672,16 @@ class optional : public optional_detail: return *this ; } +#ifdef BOOST_HAS_RVALUE_REFS + // Assigns from a T (moves the rhs value) + // Basic Guarantee: If T::( T && ) throws, this is left UNINITIALIZED + optional& operator= ( rreference_type val ) + { + this->assign( std::forward(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) @@ -671,6 +746,24 @@ optional make_optional ( bool cond, T return optional(cond,v); } +#ifdef BOOST_HAS_RVALUE_REFS +// Returns optional(v) +template +inline +optional make_optional ( T && v ) +{ + return optional(std::forward(v)); +} + +// Returns optional(cond,v) +template +inline +optional make_optional ( bool cond, T && v ) +{ + return optional(cond,std::forward(v)); +} +#endif + // Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED. // No-throw template