From 3499d477dcce68d7b055c9a7e4a162336b57029a Mon Sep 17 00:00:00 2001 From: Fernando Cacciola Date: Fri, 2 Nov 2007 22:56:23 +0000 Subject: [PATCH] Merged changests from RC_1_34_0 - base rev 33417 [SVN r40705] --- include/boost/optional/optional.hpp | 133 ++++++++++++++++++++++++---- 1 file changed, 115 insertions(+), 18 deletions(-) diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 8a78a40..42277ba 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -26,7 +26,7 @@ #include "boost/mpl/bool.hpp" #include "boost/mpl/not.hpp" #include "boost/detail/reference_content.hpp" -#include "boost/none_t.hpp" +#include "boost/none.hpp" #include "boost/utility/compare_pointees.hpp" #include "boost/optional/optional_fwd.hpp" @@ -76,6 +76,19 @@ #define BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION #endif +// Daniel Wallin discovered that bind/apply.hpp badly interacts with the apply<> +// member template of a factory as used in the optional<> implementation. +// He proposed this simple fix which is to move the call to apply<> outside +// namespace boost. +namespace boost_optional_detail +{ + template + void construct(Factory const& factory, void* address) + { + factory.BOOST_NESTED_TEMPLATE apply(address); + } +} + namespace boost { @@ -173,7 +186,7 @@ class optional_base : public optional_tag // Creates an optional uninitialized. // No-throw - optional_base ( none_t const& ) + optional_base ( none_t ) : m_initialized(false) {} @@ -266,7 +279,7 @@ class optional_base : public optional_tag // Assigns from "none", destroying the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) - void assign ( none_t const& ) { destroy(); } + void assign ( none_t ) { destroy(); } #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT template @@ -309,7 +322,7 @@ class optional_base : public optional_tag void construct ( Expr const& factory, in_place_factory_base const* ) { BOOST_STATIC_ASSERT ( ::boost::mpl::not_::value ) ; - factory.BOOST_NESTED_TEMPLATE apply(m_storage.address()) ; + boost_optional_detail::construct(factory, m_storage.address()); m_initialized = true ; } @@ -428,6 +441,8 @@ class optional_base : public optional_tag // the following olverloads are used to filter out the case and guarantee an error in case of T being a reference. pointer_const_type cast_ptr( internal_type const* p, is_not_reference_tag ) const { return p ; } pointer_type cast_ptr( internal_type * p, is_not_reference_tag ) { return p ; } + pointer_const_type cast_ptr( internal_type const* p, is_reference_tag ) const { return &p->get() ; } + pointer_type cast_ptr( internal_type * p, is_reference_tag ) { return &p->get() ; } bool m_initialized ; storage_type m_storage ; @@ -459,7 +474,7 @@ class optional : public optional_detail::optional_base // Creates an optional uninitialized. // No-throw - optional( none_t const& none_ ) : base(none_) {} + optional( none_t none_ ) : base(none_) {} // Creates an optional initialized with 'val'. // Can throw if T::T(T const&) does @@ -550,7 +565,7 @@ class optional : public optional_detail::optional_base // Assigns from a "none" // Which destroys the current value, if any, leaving this UNINITIALIZED // No-throw (assuming T::~T() doesn't) - optional& operator= ( none_t const& none_ ) + optional& operator= ( none_t none_ ) { this->assign( none_ ) ; return *this ; @@ -678,6 +693,11 @@ get_pointer ( optional& opt ) // optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values). // WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead. + +// +// optional vs optional cases +// + template inline bool operator == ( optional const& x, optional const& y ) @@ -708,64 +728,141 @@ inline bool operator >= ( optional const& x, optional const& y ) { return !( x < y ) ; } + +// +// optional vs T cases +// template inline -bool operator == ( optional const& x, none_t const& ) +bool operator == ( optional const& x, T const& y ) +{ return equal_pointees(x, optional(y)); } + +template +inline +bool operator < ( optional const& x, T const& y ) +{ return less_pointees(x, optional(y)); } + +template +inline +bool operator != ( optional const& x, T const& y ) +{ return !( x == y ) ; } + +template +inline +bool operator > ( optional const& x, T const& y ) +{ return y < x ; } + +template +inline +bool operator <= ( optional const& x, T const& y ) +{ return !( y < x ) ; } + +template +inline +bool operator >= ( optional const& x, T const& y ) +{ return !( x < y ) ; } + +// +// T vs optional cases +// + +template +inline +bool operator == ( T const& x, optional const& y ) +{ return equal_pointees( optional(x), y ); } + +template +inline +bool operator < ( T const& x, optional const& y ) +{ return less_pointees( optional(x), y ); } + +template +inline +bool operator != ( T const& x, optional const& y ) +{ return !( x == y ) ; } + +template +inline +bool operator > ( T const& x, optional const& y ) +{ return y < x ; } + +template +inline +bool operator <= ( T const& x, optional const& y ) +{ return !( y < x ) ; } + +template +inline +bool operator >= ( T const& x, optional const& y ) +{ return !( x < y ) ; } + + +// +// optional vs none cases +// + +template +inline +bool operator == ( optional const& x, none_t ) { return equal_pointees(x, optional() ); } template inline -bool operator < ( optional const& x, none_t const& ) +bool operator < ( optional const& x, none_t ) { return less_pointees(x,optional() ); } template inline -bool operator != ( optional const& x, none_t const& y ) +bool operator != ( optional const& x, none_t y ) { return !( x == y ) ; } template inline -bool operator > ( optional const& x, none_t const& y ) +bool operator > ( optional const& x, none_t y ) { return y < x ; } template inline -bool operator <= ( optional const& x, none_t const& y ) +bool operator <= ( optional const& x, none_t y ) { return !( y < x ) ; } template inline -bool operator >= ( optional const& x, none_t const& y ) +bool operator >= ( optional const& x, none_t y ) { return !( x < y ) ; } +// +// none vs optional cases +// + template inline -bool operator == ( none_t const& x, optional const& y ) +bool operator == ( none_t x, optional const& y ) { return equal_pointees(optional() ,y); } template inline -bool operator < ( none_t const& x, optional const& y ) +bool operator < ( none_t x, optional const& y ) { return less_pointees(optional() ,y); } template inline -bool operator != ( none_t const& x, optional const& y ) +bool operator != ( none_t x, optional const& y ) { return !( x == y ) ; } template inline -bool operator > ( none_t const& x, optional const& y ) +bool operator > ( none_t x, optional const& y ) { return y < x ; } template inline -bool operator <= ( none_t const& x, optional const& y ) +bool operator <= ( none_t x, optional const& y ) { return !( y < x ) ; } template inline -bool operator >= ( none_t const& x, optional const& y ) +bool operator >= ( none_t x, optional const& y ) { return !( x < y ) ; } //