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]
This commit is contained in:
Fernando Cacciola
2006-02-03 19:56:03 +00:00
parent a6f4615d5f
commit e1ffaf38b6

View File

@ -29,6 +29,8 @@
#include "boost/none_t.hpp" #include "boost/none_t.hpp"
#include "boost/utility/compare_pointees.hpp" #include "boost/utility/compare_pointees.hpp"
#include "boost/optional/optional_fwd.hpp"
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200) #if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
// VC6.0 has the following bug: // VC6.0 has the following bug:
// When a templated assignment operator exist, an implicit conversion // When a templated assignment operator exist, an implicit conversion
@ -223,6 +225,23 @@ class optional_base : public optional_tag
} }
} }
// Assigns from another _convertible_ optional<U> (deep-copies the rhs value)
template<class U>
void assign ( optional<U> const& rhs )
{
if (is_initialized())
{
if ( rhs.is_initialized() )
assign_value(static_cast<value_type>(rhs.get()), is_reference_predicate() );
else destroy();
}
else
{
if ( rhs.is_initialized() )
construct(static_cast<value_type>(rhs.get()));
}
}
// Assigns from a T (deep-copies the rhs value) // Assigns from a T (deep-copies the rhs value)
void assign ( argument_type val ) void assign ( argument_type val )
{ {
@ -481,6 +500,7 @@ class optional : public optional_detail::optional_base<T>
} }
#endif #endif
#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT #ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
// Assigns from another convertible optional<U> (converts && deep-copies the rhs value) // Assigns from another convertible optional<U> (converts && deep-copies the rhs value)
// Requires a valid conversion from U to T. // Requires a valid conversion from U to T.
@ -488,7 +508,7 @@ class optional : public optional_detail::optional_base<T>
template<class U> template<class U>
optional& operator= ( optional<U> const& rhs ) optional& operator= ( optional<U> const& rhs )
{ {
this->assign(rhs.get()); this->assign(rhs);
return *this ; return *this ;
} }
#endif #endif