From e1ffaf38b61d57452c8854ac09acb4ed96702942 Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Fri, 3 Feb 2006 19:56:03 +0000 Subject: [PATCH] Fixed the converting assignment bug in optional<> Fixed the usage of 'None' in converter.h, which is declared as a macro in X11/X.h [SVN r32531] --- include/boost/optional/optional.hpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 99f3af0..4b013a4 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -29,6 +29,8 @@ #include "boost/none_t.hpp" #include "boost/utility/compare_pointees.hpp" +#include "boost/optional/optional_fwd.hpp" + #if BOOST_WORKAROUND(BOOST_MSVC, == 1200) // VC6.0 has the following bug: // When a templated assignment operator exist, an implicit conversion @@ -223,6 +225,23 @@ class optional_base : public optional_tag } } + // Assigns from another _convertible_ optional (deep-copies the rhs value) + template + void assign ( optional const& rhs ) + { + 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())); + } + } + // Assigns from a T (deep-copies the rhs value) void assign ( argument_type val ) { @@ -481,6 +500,7 @@ class optional : public optional_detail::optional_base } #endif + #ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT // Assigns from another convertible optional (converts && deep-copies the rhs value) // Requires a valid conversion from U to T. @@ -488,7 +508,7 @@ class optional : public optional_detail::optional_base template optional& operator= ( optional const& rhs ) { - this->assign(rhs.get()); + this->assign(rhs); return *this ; } #endif