diff --git a/include/boost/optional.hpp b/include/boost/optional.hpp index c5a8546..e28fb79 100644 --- a/include/boost/optional.hpp +++ b/include/boost/optional.hpp @@ -25,14 +25,8 @@ #include "boost/type_traits/alignment_of.hpp" #include "boost/type_traits/type_with_alignment.hpp" -// MSVC6.0 doesn't like separated templated contructor/assignment, -#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200 ) // 1200 == VC++ 6.0 -#define BOOST_OPTIONAL_NO_CONVERTIONS -#endif - namespace boost { - namespace optional_detail { template @@ -80,17 +74,8 @@ class optional construct(val); } - // Creates a deep copy of another optional - // Can throw if T::T(T const&) does - optional ( optional const& rhs ) - : - m_initialized(false) - { - if ( rhs ) - construct(*rhs); - } - -#ifndef BOOST_OPTIONAL_NO_CONVERTIONS + // NOTE: MSVC needs templated versions first + // Creates a deep copy of another convertible optional // Requires a valid conversion from U to T. // Can throw if T::T(U const&) does @@ -102,27 +87,21 @@ class optional if ( rhs ) construct(*rhs); } -#endif + + // Creates a deep copy of another optional + // Can throw if T::T(T const&) does + optional ( optional const& rhs ) + : + m_initialized(false) + { + if ( rhs ) + construct(*rhs); + } + // No-throw (assuming T::~T() doesn't) ~optional() { destroy() ; } - // Assigns from another optional (deep-copies the rhs value) - // Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED - optional& operator= ( optional const& rhs ) - { - destroy(); // no-throw - - if ( rhs ) - { - // An exception can be thrown here. - // It it happens, THIS will be left uninitialized. - construct(*rhs); - } - return *this ; - } - -#ifndef BOOST_OPTIONAL_NO_CONVERTIONS // 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 @@ -139,7 +118,22 @@ class optional } return *this ; } -#endif + + // Assigns from another optional (deep-copies the rhs value) + // Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED + optional& operator= ( optional const& rhs ) + { + destroy(); // no-throw + + if ( rhs ) + { + // An exception can be thrown here. + // It it happens, THIS will be left uninitialized. + construct(*rhs); + } + return *this ; + } + // Destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) diff --git a/test/optional_test.cpp b/test/optional_test.cpp index 2c3181f..c2d0139 100644 --- a/test/optional_test.cpp +++ b/test/optional_test.cpp @@ -876,7 +876,6 @@ void test_no_implicit_conversions() test_no_implicit_conversions_impl(p); } -#ifndef BOOST_OPTIONAL_NO_CONVERTIONS struct A {} ; void test_conversions() { @@ -895,7 +894,6 @@ void test_conversions() opt3 = opt2 ; BOOST_CHECK(*opt3 == d); } -#endif int test_main( int, char* [] ) { @@ -904,11 +902,7 @@ int test_main( int, char* [] ) test_with_class_type(); test_with_builtin_types(); test_no_implicit_conversions(); - -#ifndef BOOST_OPTIONAL_NO_CONVERTIONS test_conversions(); -#endif - } catch ( ... ) {