forked from boostorg/optional
Compare commits
1 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
9dfbbef796 |
File diff suppressed because it is too large
Load Diff
@ -1,43 +1,31 @@
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
// Copyright (C) 2007, Anthony Williams
|
||||
// Copyright (C) 2007, Steven Watanabe, Richard Smith
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional/ for documentation.
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// fernando.cacciola@gmail.com
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
#ifndef BOOST_NONE_17SEP2003_HPP
|
||||
#define BOOST_NONE_17SEP2003_HPP
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class none_helper;
|
||||
}
|
||||
#include "boost/detail/none_t.hpp"
|
||||
|
||||
inline void none(detail::none_helper);
|
||||
// NOTE: Borland users have to include this header outside any precompiled headers
|
||||
// (bcc<=5.64 cannot include instance data in a precompiled header)
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class none_helper
|
||||
{
|
||||
private:
|
||||
|
||||
none_helper( none_helper const& ) {}
|
||||
|
||||
friend void boost::none(none_helper);
|
||||
};
|
||||
}
|
||||
namespace boost {
|
||||
|
||||
typedef void (*none_t)(detail::none_helper);
|
||||
namespace {
|
||||
|
||||
detail::none_t const none = ((detail::none_t)0) ;
|
||||
|
||||
inline void none(detail::none_helper) {}
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -26,11 +26,9 @@
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/detail/reference_content.hpp"
|
||||
#include "boost/none.hpp"
|
||||
#include "boost/detail/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
|
||||
@ -66,7 +64,7 @@
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT) \
|
||||
&& BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581) )
|
||||
&& BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
|
||||
// BCB (up to 5.64) has the following bug:
|
||||
// If there is a member function/operator template of the form
|
||||
// template<class Expr> mfunc( Expr expr ) ;
|
||||
@ -76,19 +74,6 @@
|
||||
#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 <class T, class Factory>
|
||||
void construct(Factory const& factory, void* address)
|
||||
{
|
||||
factory.BOOST_NESTED_TEMPLATE apply<T>(address);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -146,11 +131,7 @@ class optional_base : public optional_tag
|
||||
{
|
||||
private :
|
||||
|
||||
typedef
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
BOOST_DEDUCED_TYPENAME
|
||||
#endif
|
||||
::boost::detail::make_reference_content<T>::type internal_type ;
|
||||
typedef BOOST_DEDUCED_TYPENAME detail::make_reference_content<T>::type internal_type ;
|
||||
|
||||
typedef aligned_storage<internal_type> storage_type ;
|
||||
|
||||
@ -186,7 +167,7 @@ class optional_base : public optional_tag
|
||||
|
||||
// Creates an optional<T> uninitialized.
|
||||
// No-throw
|
||||
optional_base ( none_t )
|
||||
optional_base ( detail::none_t const& )
|
||||
:
|
||||
m_initialized(false) {}
|
||||
|
||||
@ -198,16 +179,6 @@ class optional_base : public optional_tag
|
||||
{
|
||||
construct(val);
|
||||
}
|
||||
|
||||
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialzed optional<T>.
|
||||
// Can throw if T::T(T const&) does
|
||||
optional_base ( bool cond, argument_type val )
|
||||
:
|
||||
m_initialized(false)
|
||||
{
|
||||
if ( cond )
|
||||
construct(val);
|
||||
}
|
||||
|
||||
// Creates a deep copy of another optional<T>
|
||||
// Can throw if T::T(T const&) does
|
||||
@ -237,57 +208,32 @@ class optional_base : public optional_tag
|
||||
~optional_base() { destroy() ; }
|
||||
|
||||
// Assigns from another optional<T> (deep-copies the rhs value)
|
||||
// Basic Guarantee: If T::T( T const& ) throws, this is left UNINITIALIZED
|
||||
void assign ( optional_base const& rhs )
|
||||
{
|
||||
if (is_initialized())
|
||||
{
|
||||
if ( rhs.is_initialized() )
|
||||
assign_value(rhs.get_impl(), is_reference_predicate() );
|
||||
else destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
destroy();
|
||||
if ( rhs.is_initialized() )
|
||||
construct(rhs.get_impl());
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
// Basic Guarantee: If T::( T const& ) throws, this is left UNINITIALIZED
|
||||
void assign ( argument_type val )
|
||||
{
|
||||
if (is_initialized())
|
||||
assign_value(val, is_reference_predicate() );
|
||||
else construct(val);
|
||||
}
|
||||
{
|
||||
destroy();
|
||||
construct(val);
|
||||
}
|
||||
|
||||
// Assigns from "none", destroying the current value, if any, leaving this UNINITIALIZED
|
||||
// No-throw (assuming T::~T() doesn't)
|
||||
void assign ( none_t ) { destroy(); }
|
||||
void assign ( detail::none_t const& ) { destroy(); }
|
||||
|
||||
#ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT
|
||||
template<class Expr>
|
||||
void assign_expr ( Expr const& expr, Expr const* tag )
|
||||
{
|
||||
if (is_initialized())
|
||||
assign_expr_to_initialized(expr,tag);
|
||||
else construct(expr,tag);
|
||||
destroy();
|
||||
construct(expr,tag);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -298,6 +244,7 @@ class optional_base : public optional_tag
|
||||
void reset() { destroy(); }
|
||||
|
||||
// Replaces the current value -if any- with 'val'
|
||||
// Basic Guarantee: If T::T( T const& ) throws this is left UNINITIALIZED.
|
||||
void reset ( argument_type val ) { assign(val); }
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise,
|
||||
@ -322,7 +269,7 @@ class optional_base : public optional_tag
|
||||
void construct ( Expr const& factory, in_place_factory_base const* )
|
||||
{
|
||||
BOOST_STATIC_ASSERT ( ::boost::mpl::not_<is_reference_predicate>::value ) ;
|
||||
boost_optional_detail::construct<value_type>(factory, m_storage.address());
|
||||
factory.BOOST_NESTED_TEMPLATE apply<value_type>(m_storage.address()) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
@ -334,21 +281,6 @@ class optional_base : public optional_tag
|
||||
factory.apply(m_storage.address()) ;
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
template<class Expr>
|
||||
void assign_expr_to_initialized ( Expr const& factory, in_place_factory_base const* tag )
|
||||
{
|
||||
destroy();
|
||||
construct(factory,tag);
|
||||
}
|
||||
|
||||
// Constructs in-place using the given typed factory
|
||||
template<class Expr>
|
||||
void assign_expr_to_initialized ( Expr const& factory, typed_in_place_factory_base const* tag )
|
||||
{
|
||||
destroy();
|
||||
construct(factory,tag);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Constructs using any expression implicitely convertible to the single argument
|
||||
@ -362,16 +294,6 @@ class optional_base : public optional_tag
|
||||
m_initialized = true ;
|
||||
}
|
||||
|
||||
// Assigns using a form any expression implicitely convertible to the single argument
|
||||
// of a T's assignment operator.
|
||||
// Converting assignments of optional<T> from optional<U> uses this function with
|
||||
// 'Expr' being of type 'U' and relying on a converting assignment of T from U.
|
||||
template<class Expr>
|
||||
void assign_expr_to_initialized ( Expr const& expr, void const* )
|
||||
{
|
||||
assign_value(expr, is_reference_predicate());
|
||||
}
|
||||
|
||||
#ifdef BOOST_OPTIONAL_WEAK_OVERLOAD_RESOLUTION
|
||||
// BCB5.64 (and probably lower versions) workaround.
|
||||
// The in-place factories are supported by means of catch-all constructors
|
||||
@ -399,14 +321,11 @@ class optional_base : public optional_tag
|
||||
}
|
||||
#endif
|
||||
|
||||
void assign_value ( argument_type val, is_not_reference_tag ) { get_impl() = val; }
|
||||
void assign_value ( argument_type val, is_reference_tag ) { construct(val); }
|
||||
|
||||
void destroy()
|
||||
{
|
||||
if ( m_initialized )
|
||||
destroy_impl(is_reference_predicate()) ;
|
||||
}
|
||||
{
|
||||
if ( m_initialized )
|
||||
destroy_impl(is_reference_predicate()) ;
|
||||
}
|
||||
|
||||
unspecified_bool_type safe_bool() const { return m_initialized ? &this_type::is_initialized : 0 ; }
|
||||
|
||||
@ -428,7 +347,7 @@ class optional_base : public optional_tag
|
||||
reference_const_type dereference( internal_type const* p, is_reference_tag ) const { return p->get() ; }
|
||||
reference_type dereference( internal_type* p, is_reference_tag ) { return p->get() ; }
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x581))
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
|
||||
void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->internal_type::~internal_type() ; m_initialized = false ; }
|
||||
#else
|
||||
void destroy_impl ( is_not_reference_tag ) { get_ptr_impl()->T::~T() ; m_initialized = false ; }
|
||||
@ -441,8 +360,6 @@ 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 ;
|
||||
@ -474,15 +391,12 @@ class optional : public optional_detail::optional_base<T>
|
||||
|
||||
// Creates an optional<T> uninitialized.
|
||||
// No-throw
|
||||
optional( none_t none_ ) : base(none_) {}
|
||||
optional( detail::none_t const& none_ ) : base(none_) {}
|
||||
|
||||
// Creates an optional<T> initialized with 'val'.
|
||||
// Can throw if T::T(T const&) does
|
||||
optional ( argument_type val ) : base(val) {}
|
||||
|
||||
// Creates an optional<T> initialized with 'val' IFF cond is true, otherwise creates an uninitialized optional.
|
||||
// Can throw if T::T(T const&) does
|
||||
optional ( bool cond, argument_type val ) : base(cond,val) {}
|
||||
|
||||
#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
|
||||
// NOTE: MSVC needs templated versions first
|
||||
@ -532,7 +446,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
|
||||
// Assigns from another convertible optional<U> (converts && deep-copies the rhs value)
|
||||
// Requires a valid conversion from U to T.
|
||||
@ -540,7 +453,14 @@ class optional : public optional_detail::optional_base<T>
|
||||
template<class U>
|
||||
optional& operator= ( optional<U> const& rhs )
|
||||
{
|
||||
this->assign(rhs);
|
||||
this->destroy(); // no-throw
|
||||
|
||||
if ( rhs.is_initialized() )
|
||||
{
|
||||
// An exception can be thrown here.
|
||||
// It it happens, THIS will be left uninitialized.
|
||||
this->assign(rhs.get());
|
||||
}
|
||||
return *this ;
|
||||
}
|
||||
#endif
|
||||
@ -565,7 +485,7 @@ class optional : public optional_detail::optional_base<T>
|
||||
// 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 none_ )
|
||||
optional& operator= ( detail::none_t const& none_ )
|
||||
{
|
||||
this->assign( none_ ) ;
|
||||
return *this ;
|
||||
@ -577,10 +497,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
reference_const_type get() const { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); }
|
||||
reference_type get() { BOOST_ASSERT(this->is_initialized()) ; return this->get_impl(); }
|
||||
|
||||
// Returns a copy of the value if this is initialized, 'v' otherwise
|
||||
reference_const_type get_value_or ( reference_const_type v ) const { return this->is_initialized() ? get() : v ; }
|
||||
reference_type get_value_or ( reference_type v ) { return this->is_initialized() ? get() : v ; }
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise,
|
||||
// the behaviour is UNDEFINED
|
||||
// No-throw
|
||||
@ -602,22 +518,6 @@ class optional : public optional_detail::optional_base<T>
|
||||
bool operator!() const { return !this->is_initialized() ; }
|
||||
} ;
|
||||
|
||||
// Returns optional<T>(v)
|
||||
template<class T>
|
||||
inline
|
||||
optional<T> make_optional ( T const& v )
|
||||
{
|
||||
return optional<T>(v);
|
||||
}
|
||||
|
||||
// Returns optional<T>(cond,v)
|
||||
template<class T>
|
||||
inline
|
||||
optional<T> make_optional ( bool cond, T const& v )
|
||||
{
|
||||
return optional<T>(cond,v);
|
||||
}
|
||||
|
||||
// Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED.
|
||||
// No-throw
|
||||
template<class T>
|
||||
@ -654,24 +554,6 @@ get ( optional<T>* opt )
|
||||
return opt->get_ptr() ;
|
||||
}
|
||||
|
||||
// Returns a reference to the value if this is initialized, otherwise, the behaviour is UNDEFINED.
|
||||
// No-throw
|
||||
template<class T>
|
||||
inline
|
||||
BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type
|
||||
get_optional_value_or ( optional<T> const& opt, BOOST_DEDUCED_TYPENAME optional<T>::reference_const_type v )
|
||||
{
|
||||
return opt.get_value_or(v) ;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
BOOST_DEDUCED_TYPENAME optional<T>::reference_type
|
||||
get_optional_value_or ( optional<T>& opt, BOOST_DEDUCED_TYPENAME optional<T>::reference_type v )
|
||||
{
|
||||
return opt.get_value_or(v) ;
|
||||
}
|
||||
|
||||
// Returns a pointer to the value if this is initialized, otherwise, returns NULL.
|
||||
// No-throw
|
||||
template<class T>
|
||||
@ -693,11 +575,6 @@ get_pointer ( optional<T>& 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<T> vs optional<T> cases
|
||||
//
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator == ( optional<T> const& x, optional<T> const& y )
|
||||
@ -728,141 +605,64 @@ inline
|
||||
bool operator >= ( optional<T> const& x, optional<T> const& y )
|
||||
{ return !( x < y ) ; }
|
||||
|
||||
|
||||
//
|
||||
// optional<T> vs T cases
|
||||
//
|
||||
template<class T>
|
||||
inline
|
||||
bool operator == ( optional<T> const& x, T const& y )
|
||||
{ return equal_pointees(x, optional<T>(y)); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator < ( optional<T> const& x, T const& y )
|
||||
{ return less_pointees(x, optional<T>(y)); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator != ( optional<T> const& x, T const& y )
|
||||
{ return !( x == y ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator > ( optional<T> const& x, T const& y )
|
||||
{ return y < x ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator <= ( optional<T> const& x, T const& y )
|
||||
{ return !( y < x ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator >= ( optional<T> const& x, T const& y )
|
||||
{ return !( x < y ) ; }
|
||||
|
||||
//
|
||||
// T vs optional<T> cases
|
||||
//
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator == ( T const& x, optional<T> const& y )
|
||||
{ return equal_pointees( optional<T>(x), y ); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator < ( T const& x, optional<T> const& y )
|
||||
{ return less_pointees( optional<T>(x), y ); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator != ( T const& x, optional<T> const& y )
|
||||
{ return !( x == y ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator > ( T const& x, optional<T> const& y )
|
||||
{ return y < x ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator <= ( T const& x, optional<T> const& y )
|
||||
{ return !( y < x ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator >= ( T const& x, optional<T> const& y )
|
||||
{ return !( x < y ) ; }
|
||||
|
||||
|
||||
//
|
||||
// optional<T> vs none cases
|
||||
//
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator == ( optional<T> const& x, none_t )
|
||||
bool operator == ( optional<T> const& x, detail::none_t const& )
|
||||
{ return equal_pointees(x, optional<T>() ); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator < ( optional<T> const& x, none_t )
|
||||
bool operator < ( optional<T> const& x, detail::none_t const& )
|
||||
{ return less_pointees(x,optional<T>() ); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator != ( optional<T> const& x, none_t y )
|
||||
bool operator != ( optional<T> const& x, detail::none_t const& y )
|
||||
{ return !( x == y ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator > ( optional<T> const& x, none_t y )
|
||||
bool operator > ( optional<T> const& x, detail::none_t const& y )
|
||||
{ return y < x ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator <= ( optional<T> const& x, none_t y )
|
||||
bool operator <= ( optional<T> const& x, detail::none_t const& y )
|
||||
{ return !( y < x ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator >= ( optional<T> const& x, none_t y )
|
||||
bool operator >= ( optional<T> const& x, detail::none_t const& y )
|
||||
{ return !( x < y ) ; }
|
||||
|
||||
//
|
||||
// none vs optional<T> cases
|
||||
//
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator == ( none_t x, optional<T> const& y )
|
||||
bool operator == ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return equal_pointees(optional<T>() ,y); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator < ( none_t x, optional<T> const& y )
|
||||
bool operator < ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return less_pointees(optional<T>() ,y); }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator != ( none_t x, optional<T> const& y )
|
||||
bool operator != ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return !( x == y ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator > ( none_t x, optional<T> const& y )
|
||||
bool operator > ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return y < x ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator <= ( none_t x, optional<T> const& y )
|
||||
bool operator <= ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return !( y < x ) ; }
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool operator >= ( none_t x, optional<T> const& y )
|
||||
bool operator >= ( detail::none_t const& x, optional<T> const& y )
|
||||
{ return !( x < y ) ; }
|
||||
|
||||
//
|
||||
@ -879,9 +679,8 @@ namespace optional_detail {
|
||||
#endif
|
||||
|
||||
// optional's swap:
|
||||
// If both are initialized, calls swap(T&, T&). If this swap throws, both will remain initialized but their values are now unspecified.
|
||||
// If only one is initialized, calls U.reset(*I), THEN I.reset().
|
||||
// If U.reset(*I) throws, both are left UNCHANGED (U is kept uinitialized and I is never reset)
|
||||
// If both are initialized, calls swap(T&, T&), with whatever exception guarantess are given there.
|
||||
// If only one is initialized, calls I.reset() and U.reset(*I), with the Basic Guarantee
|
||||
// If both are uninitialized, do nothing (no-throw)
|
||||
template<class T>
|
||||
inline
|
||||
@ -889,12 +688,12 @@ void optional_swap ( optional<T>& x, optional<T>& y )
|
||||
{
|
||||
if ( !x && !!y )
|
||||
{
|
||||
x.reset(*y);
|
||||
x.reset(*y); // Basic guarantee.
|
||||
y.reset();
|
||||
}
|
||||
else if ( !!x && !y )
|
||||
{
|
||||
y.reset(*x);
|
||||
y.reset(*x); // Basic guarantee.
|
||||
x.reset();
|
||||
}
|
||||
else if ( !!x && !!y )
|
||||
@ -915,7 +714,6 @@ template<class T> inline void swap ( optional<T>& x, optional<T>& y )
|
||||
optional_detail::optional_swap(x,y);
|
||||
}
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
@ -1,84 +0,0 @@
|
||||
// Copyright (C) 2005, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
#ifndef BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
|
||||
#define BOOST_OPTIONAL_OPTIONAL_IO_FLC_19NOV2002_HPP
|
||||
|
||||
#if defined __GNUC__
|
||||
# if (__GNUC__ == 2 && __GNUC_MINOR__ <= 97)
|
||||
# define BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
|
||||
# endif
|
||||
#endif // __GNUC__
|
||||
|
||||
#if defined BOOST_OPTIONAL_NO_TEMPLATED_STREAMS
|
||||
# include <iostream>
|
||||
#else
|
||||
# include <istream>
|
||||
# include <ostream>
|
||||
#endif
|
||||
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
#include "boost/utility/value_init.hpp"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
||||
template<class T>
|
||||
inline std::ostream& operator<<(std::ostream& out, optional<T> const& v)
|
||||
#else
|
||||
template<class CharType, class CharTrait, class T>
|
||||
inline
|
||||
std::basic_ostream<CharType, CharTrait>&
|
||||
operator<<(std::basic_ostream<CharType, CharTrait>& out, optional<T> const& v)
|
||||
#endif
|
||||
{
|
||||
if ( out.good() )
|
||||
{
|
||||
if ( !v )
|
||||
out << "--" ;
|
||||
else out << ' ' << *v ;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#if defined (BOOST_NO_TEMPLATED_STREAMS)
|
||||
template<class T>
|
||||
inline std::istream& operator>>(std::istream& in, optional<T>& v)
|
||||
#else
|
||||
template<class CharType, class CharTrait, class T>
|
||||
inline
|
||||
std::basic_istream<CharType, CharTrait>&
|
||||
operator>>(std::basic_istream<CharType, CharTrait>& in, optional<T>& v)
|
||||
#endif
|
||||
{
|
||||
if ( in.good() )
|
||||
{
|
||||
int d = in.get();
|
||||
if ( d == ' ' )
|
||||
{
|
||||
T x ;
|
||||
in >> x;
|
||||
v = x ;
|
||||
}
|
||||
else
|
||||
v = optional<T>() ;
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif
|
||||
|
@ -4,10 +4,6 @@
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="doc/optional.html">doc/optional.html</a>. <hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<a href="doc/optional.html">doc/optional.html</a>.
|
||||
</body>
|
||||
</html>
|
36
test/Jamfile
Normal file
36
test/Jamfile
Normal file
@ -0,0 +1,36 @@
|
||||
# Boost.Optional Library test Jamfile
|
||||
#
|
||||
# Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
#
|
||||
# Use, modification, and distribution is subject to the Boost Software
|
||||
# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
|
||||
subproject libs/optional/test ;
|
||||
|
||||
# bring in rules for testing
|
||||
SEARCH on testing.jam = $(BOOST_BUILD_PATH) ;
|
||||
include testing.jam ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
test-suite optional :
|
||||
[ run optional_test.cpp ]
|
||||
[ run optional_test_tie.cpp ]
|
||||
[ run optional_test_ref.cpp ]
|
||||
[ run optional_test_inplace.cpp ]
|
||||
[ compile-fail optional_test_fail1.cpp ]
|
||||
[ compile-fail optional_test_fail2.cpp ]
|
||||
[ compile-fail optional_test_fail3a.cpp ]
|
||||
[ compile-fail optional_test_fail3b.cpp ]
|
||||
[ compile-fail optional_test_ref_fail1.cpp ]
|
||||
[ compile-fail optional_test_ref_fail2.cpp ]
|
||||
[ compile-fail optional_test_ref_fail3.cpp ]
|
||||
[ compile-fail optional_test_ref_fail4.cpp ]
|
||||
[ compile-fail optional_test_inplace_fail.cpp ]
|
||||
[ compile-fail optional_test_inplace_fail2.cpp ]
|
||||
;
|
||||
}
|
@ -20,11 +20,12 @@ import testing ;
|
||||
[ run optional_test_tie.cpp ]
|
||||
[ run optional_test_ref.cpp ]
|
||||
[ run optional_test_inplace.cpp ]
|
||||
[ run optional_test_io.cpp ]
|
||||
[ compile-fail optional_test_fail1.cpp ]
|
||||
[ compile-fail optional_test_fail2.cpp ]
|
||||
[ compile-fail optional_test_fail3a.cpp ]
|
||||
[ compile-fail optional_test_fail3b.cpp ]
|
||||
[ compile-fail optional_test_ref_fail1.cpp ]
|
||||
[ compile-fail optional_test_ref_fail2.cpp ]
|
||||
[ compile-fail optional_test_ref_fail3.cpp ]
|
||||
[ compile-fail optional_test_ref_fail4.cpp ]
|
||||
[ compile-fail optional_test_inplace_fail.cpp ]
|
||||
|
@ -15,9 +15,7 @@
|
||||
|
||||
#define BOOST_ENABLE_ASSERT_HANDLER
|
||||
|
||||
#include "boost/bind/apply.hpp" // Included just to test proper interaction with boost::apply<> as reported by Daniel Wallin
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
@ -72,7 +70,7 @@ void test_basics( T const* )
|
||||
// Implicit construction
|
||||
// The first parameter is implicitely converted to optional<T>(a);
|
||||
test_implicit_construction(a,a,z);
|
||||
|
||||
|
||||
// Direct initialization.
|
||||
// 'oa' state is Initialized with 'a'
|
||||
// T::T( T const& x ) is used.
|
||||
@ -87,7 +85,7 @@ void test_basics( T const* )
|
||||
optional<T> ob ;
|
||||
|
||||
// Value-Assignment upon Uninitialized optional.
|
||||
// T::T( T const& x ) is used.
|
||||
// T::T ( T const& x ) is used.
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
ob = a ;
|
||||
check_is_not_pending_copy( ARG(T) ) ;
|
||||
@ -95,14 +93,12 @@ void test_basics( T const* )
|
||||
check_value(ob,a,z);
|
||||
|
||||
// Value-Assignment upon Initialized optional.
|
||||
// T::operator=( T const& x ) is used
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
set_pending_copy ( ARG(T) ) ;
|
||||
set_pending_dtor ( ARG(T) ) ;
|
||||
// T::T ( T const& x ) is used
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
ob = b ;
|
||||
check_is_not_pending_assign( ARG(T) ) ;
|
||||
check_is_pending_copy ( ARG(T) ) ;
|
||||
check_is_pending_dtor ( ARG(T) ) ;
|
||||
check_is_not_pending_dtor( ARG(T) ) ;
|
||||
check_is_not_pending_copy( ARG(T) ) ;
|
||||
check_initialized(ob);
|
||||
check_value(ob,b,z);
|
||||
|
||||
@ -115,10 +111,13 @@ void test_basics( T const* )
|
||||
check_value_const(oa2,a,z);
|
||||
|
||||
// Assignment
|
||||
// T::operator= ( T const& x ) is used to copy new value.
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
// T::~T() is used to destroy previous value in ob.
|
||||
// T::T ( T const& x ) is used to copy new value.
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
oa = ob ;
|
||||
check_is_not_pending_assign( ARG(T) ) ;
|
||||
check_is_not_pending_dtor( ARG(T) ) ;
|
||||
check_is_not_pending_copy( ARG(T) ) ;
|
||||
check_initialized(oa);
|
||||
check_value(oa,b,z);
|
||||
|
||||
@ -153,95 +152,6 @@ void test_basics( T const* )
|
||||
ob.reset();
|
||||
check_is_pending_dtor( ARG(T) ) ;
|
||||
check_uninitialized(ob);
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test_conditional_ctor_and_get_valur_or ( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
T a(321);
|
||||
|
||||
T z(123);
|
||||
|
||||
optional<T> const cdef0(false,a);
|
||||
|
||||
optional<T> def0(false,a);
|
||||
optional<T> def1 = boost::make_optional(false,a); // T is not within boost so ADL won't find make_optional unqualified
|
||||
check_uninitialized(def0);
|
||||
check_uninitialized(def1);
|
||||
|
||||
optional<T> const co0(true,a);
|
||||
|
||||
optional<T> o0(true,a);
|
||||
optional<T> o1 = boost::make_optional(true,a); // T is not within boost so ADL won't find make_optional unqualified
|
||||
|
||||
check_initialized(o0);
|
||||
check_initialized(o1);
|
||||
check_value(o0,a,z);
|
||||
check_value(o1,a,z);
|
||||
|
||||
T b = def0.get_value_or(z);
|
||||
BOOST_CHECK( b == z ) ;
|
||||
|
||||
b = get_optional_value_or(def0,z);
|
||||
BOOST_CHECK( b == z ) ;
|
||||
|
||||
b = o0.get_value_or(z);
|
||||
BOOST_CHECK( b == a ) ;
|
||||
|
||||
b = get_optional_value_or(o0,z);
|
||||
BOOST_CHECK( b == a ) ;
|
||||
|
||||
|
||||
T const& crz = z ;
|
||||
T& rz = z ;
|
||||
|
||||
T const& crzz = def0.get_value_or(crz);
|
||||
BOOST_CHECK( crzz == crz ) ;
|
||||
|
||||
T& rzz = def0.get_value_or(rz);
|
||||
BOOST_CHECK( rzz == rz ) ;
|
||||
|
||||
T const& crzzz = get_optional_value_or(cdef0,crz);
|
||||
BOOST_CHECK( crzzz == crz ) ;
|
||||
|
||||
T& rzzz = get_optional_value_or(def0,rz);
|
||||
BOOST_CHECK( rzzz == rz ) ;
|
||||
|
||||
T const& crb = o0.get_value_or(crz);
|
||||
BOOST_CHECK( crb == a ) ;
|
||||
|
||||
T& rb = o0.get_value_or(rz);
|
||||
BOOST_CHECK( rb == b ) ;
|
||||
|
||||
T const& crbb = get_optional_value_or(co0,crz);
|
||||
BOOST_CHECK( crbb == b ) ;
|
||||
|
||||
T const& crbbb = get_optional_value_or(o0,crz);
|
||||
BOOST_CHECK( crbbb == b ) ;
|
||||
|
||||
T& rbb = get_optional_value_or(o0,rz);
|
||||
BOOST_CHECK( rbb == b ) ;
|
||||
|
||||
T& ra = a ;
|
||||
|
||||
optional<T&> defref(false,ra);
|
||||
BOOST_CHECK(!defref);
|
||||
|
||||
optional<T&> ref(true,ra);
|
||||
BOOST_CHECK(!!ref);
|
||||
|
||||
a = T(432);
|
||||
|
||||
BOOST_CHECK( *ref == a ) ;
|
||||
|
||||
T& r1 = defref.get_value_or(z);
|
||||
BOOST_CHECK( r1 == z ) ;
|
||||
|
||||
T& r2 = ref.get_value_or(z);
|
||||
BOOST_CHECK( r2 == a ) ;
|
||||
}
|
||||
|
||||
//
|
||||
@ -251,7 +161,7 @@ template<class T>
|
||||
void test_direct_value_manip( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
|
||||
T x(3);
|
||||
|
||||
optional<T> const c_opt0(x) ;
|
||||
@ -259,7 +169,7 @@ void test_direct_value_manip( T const* )
|
||||
|
||||
BOOST_CHECK( c_opt0.get().V() == x.V() ) ;
|
||||
BOOST_CHECK( opt0.get().V() == x.V() ) ;
|
||||
|
||||
|
||||
BOOST_CHECK( c_opt0->V() == x.V() ) ;
|
||||
BOOST_CHECK( opt0->V() == x.V() ) ;
|
||||
|
||||
@ -302,7 +212,7 @@ void test_uninitialized_access( T const* )
|
||||
}
|
||||
catch (...) {}
|
||||
BOOST_CHECK(!passed);
|
||||
|
||||
|
||||
passed = false ;
|
||||
try
|
||||
{
|
||||
@ -372,9 +282,6 @@ void test_throwing_direct_init( T const* )
|
||||
BOOST_CHECK(!passed);
|
||||
check_is_not_pending_copy( ARG(T) );
|
||||
check_instance_count(count, ARG(T) );
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@ -410,8 +317,6 @@ void test_throwing_val_assign_on_uninitialized( T const* )
|
||||
check_is_not_pending_copy( ARG(T) );
|
||||
check_instance_count(count, ARG(T) );
|
||||
check_uninitialized(opt);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
}
|
||||
|
||||
//
|
||||
@ -425,10 +330,11 @@ void test_throwing_val_assign_on_initialized( T const* )
|
||||
T z(0);
|
||||
T a(8);
|
||||
T b(9);
|
||||
T x(-1);
|
||||
|
||||
int count = get_instance_count( ARG(T) ) ;
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> opt ( b ) ;
|
||||
++ count ;
|
||||
|
||||
@ -436,16 +342,16 @@ void test_throwing_val_assign_on_initialized( T const* )
|
||||
|
||||
check_value(opt,b,z);
|
||||
|
||||
set_throw_on_assign( ARG(T) ) ;
|
||||
set_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
bool passed = false ;
|
||||
try
|
||||
{
|
||||
// This should:
|
||||
// Attempt to assign 'a' and throw.
|
||||
// opt is kept initialized but its value not neccesarily fully assigned
|
||||
// (in this test, incompletely assigned is flaged with the value -1 being set)
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
// Attempt to copy construct 'a' and throw.
|
||||
// opt should be left uninitialized (even though it was initialized)
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
opt.reset ( a ) ;
|
||||
passed = true ;
|
||||
}
|
||||
@ -453,12 +359,12 @@ void test_throwing_val_assign_on_initialized( T const* )
|
||||
|
||||
BOOST_CHECK(!passed);
|
||||
|
||||
check_is_not_pending_assign( ARG(T) );
|
||||
-- count ;
|
||||
|
||||
check_is_not_pending_dtor( ARG(T) );
|
||||
check_is_not_pending_copy( ARG(T) );
|
||||
check_instance_count(count, ARG(T) );
|
||||
check_initialized(opt);
|
||||
check_value(opt,x,z);
|
||||
|
||||
reset_throw_on_assign ( ARG(T) ) ;
|
||||
check_uninitialized(opt);
|
||||
}
|
||||
|
||||
//
|
||||
@ -472,6 +378,8 @@ void test_throwing_copy_initialization( T const* )
|
||||
T z(0);
|
||||
T a(10);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> opt (a);
|
||||
|
||||
int count = get_instance_count( ARG(T) ) ;
|
||||
@ -498,8 +406,6 @@ void test_throwing_copy_initialization( T const* )
|
||||
// Nothing should have happened to the source optional.
|
||||
check_initialized(opt);
|
||||
check_value(opt,a,z);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
}
|
||||
|
||||
//
|
||||
@ -514,6 +420,8 @@ void test_throwing_assign_to_uninitialized( T const* )
|
||||
T z(0);
|
||||
T a(11);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> opt0 ;
|
||||
optional<T> opt1(a) ;
|
||||
|
||||
@ -538,8 +446,6 @@ void test_throwing_assign_to_uninitialized( T const* )
|
||||
check_is_not_pending_copy( ARG(T) );
|
||||
check_instance_count(count, ARG(T) );
|
||||
check_uninitialized(opt0);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
}
|
||||
|
||||
//
|
||||
@ -554,23 +460,24 @@ void test_throwing_assign_to_initialized( T const* )
|
||||
T z(0);
|
||||
T a(12);
|
||||
T b(13);
|
||||
T x(-1);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> opt0(a) ;
|
||||
optional<T> opt1(b) ;
|
||||
|
||||
int count = get_instance_count( ARG(T) ) ;
|
||||
|
||||
set_throw_on_assign( ARG(T) ) ;
|
||||
set_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
bool passed = false ;
|
||||
try
|
||||
{
|
||||
// This should:
|
||||
// Attempt to copy construct 'opt1.value()' into opt0 and throw.
|
||||
// opt0 is kept initialized but its value not neccesarily fully assigned
|
||||
// (in this test, incompletely assigned is flaged with the value -1 being set)
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
// opt0 should be left unmodified or uninitialized
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
opt0 = opt1 ;
|
||||
passed = true ;
|
||||
}
|
||||
@ -579,12 +486,11 @@ void test_throwing_assign_to_initialized( T const* )
|
||||
BOOST_CHECK(!passed);
|
||||
|
||||
// opt0 was left uninitialized
|
||||
check_is_not_pending_assign( ARG(T) );
|
||||
-- count ;
|
||||
check_is_not_pending_dtor( ARG(T) );
|
||||
check_is_not_pending_copy( ARG(T) );
|
||||
check_instance_count(count, ARG(T) );
|
||||
check_initialized(opt0);
|
||||
check_value(opt0,x,z);
|
||||
|
||||
reset_throw_on_assign( ARG(T) ) ;
|
||||
check_uninitialized(opt0);
|
||||
}
|
||||
|
||||
//
|
||||
@ -594,11 +500,13 @@ template<class T>
|
||||
void test_no_throwing_swap( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
|
||||
T z(0);
|
||||
T a(14);
|
||||
T b(15);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> def0 ;
|
||||
optional<T> def1 ;
|
||||
optional<T> opt0(a) ;
|
||||
@ -633,15 +541,16 @@ template<class T>
|
||||
void test_throwing_swap( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
|
||||
T a(16);
|
||||
T b(17);
|
||||
T x(-1);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
optional<T> opt0(a) ;
|
||||
optional<T> opt1(b) ;
|
||||
|
||||
set_throw_on_assign( ARG(T) ) ;
|
||||
set_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
//
|
||||
// Case 1: Both Initialized.
|
||||
@ -658,18 +567,14 @@ void test_throwing_swap( T const* )
|
||||
|
||||
BOOST_CHECK(!passed);
|
||||
|
||||
// optional's swap doesn't affect the initialized states of the arguments. Therefore,
|
||||
// the following must hold:
|
||||
check_initialized(opt0);
|
||||
check_initialized(opt1);
|
||||
check_value(opt0,x,a);
|
||||
check_value(opt1,b,x);
|
||||
|
||||
// Assuming swap(T&,T&) has at least the basic guarantee, these should hold.
|
||||
BOOST_CHECK( ( !opt0 || ( !!opt0 && ( ( *opt0 == a ) || ( *opt0 == b ) ) ) ) ) ;
|
||||
BOOST_CHECK( ( !opt1 || ( !!opt1 && ( ( *opt1 == a ) || ( *opt1 == b ) ) ) ) ) ;
|
||||
|
||||
//
|
||||
// Case 2: Only one Initialized.
|
||||
//
|
||||
reset_throw_on_assign( ARG(T) ) ;
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
opt0.reset();
|
||||
opt1.reset(a);
|
||||
@ -680,7 +585,7 @@ void test_throwing_swap( T const* )
|
||||
try
|
||||
{
|
||||
// This should attempt to swap optionals and fail at opt0.reset(*opt1)
|
||||
// Both opt0 and op1 are left unchanged (unswaped)
|
||||
// opt0 should be left uninitialized and opt1 unchanged.
|
||||
swap(opt0,opt1);
|
||||
|
||||
passed = true ;
|
||||
@ -691,9 +596,7 @@ void test_throwing_swap( T const* )
|
||||
|
||||
check_uninitialized(opt0);
|
||||
check_initialized(opt1);
|
||||
check_value(opt1,a,x);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
check_value(opt1,a,b);
|
||||
}
|
||||
|
||||
//
|
||||
@ -703,17 +606,19 @@ template<class T>
|
||||
void test_relops( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
T v0(0);
|
||||
T v1(1);
|
||||
T v2(1);
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
T v0(18);
|
||||
T v1(19);
|
||||
T v2(19);
|
||||
|
||||
optional<T> def0 ;
|
||||
optional<T> def1 ;
|
||||
optional<T> opt0(v0);
|
||||
optional<T> opt1(v1);
|
||||
optional<T> opt2(v2);
|
||||
|
||||
|
||||
// Check identity
|
||||
BOOST_CHECK ( def0 == def0 ) ;
|
||||
BOOST_CHECK ( opt0 == opt0 ) ;
|
||||
@ -722,11 +627,11 @@ void test_relops( T const* )
|
||||
|
||||
// Check when both are uininitalized.
|
||||
BOOST_CHECK ( def0 == def1 ) ; // both uninitialized compare equal
|
||||
BOOST_CHECK ( !(def0 < def1) ) ; // uninitialized is never less than uninitialized
|
||||
BOOST_CHECK ( !(def0 < def1) ) ; // uninitialized is never less than uninitialized
|
||||
BOOST_CHECK ( !(def0 > def1) ) ; // uninitialized is never greater than uninitialized
|
||||
BOOST_CHECK ( !(def0 != def1) ) ;
|
||||
BOOST_CHECK ( def0 <= def1 ) ;
|
||||
BOOST_CHECK ( def0 >= def1 ) ;
|
||||
BOOST_CHECK ( def0 <= def1 ) ;
|
||||
BOOST_CHECK ( def0 >= def1 ) ;
|
||||
|
||||
// Check when only lhs is uninitialized.
|
||||
BOOST_CHECK ( def0 != opt0 ) ; // uninitialized is never equal to initialized
|
||||
@ -751,33 +656,6 @@ void test_relops( T const* )
|
||||
BOOST_CHECK ( opt1 > opt0 ) ;
|
||||
BOOST_CHECK ( opt1 <= opt2 ) ;
|
||||
BOOST_CHECK ( opt1 >= opt0 ) ;
|
||||
|
||||
// Compare against a value directly
|
||||
BOOST_CHECK ( opt0 == v0 ) ;
|
||||
BOOST_CHECK ( opt0 != v1 ) ;
|
||||
BOOST_CHECK ( opt1 == v2 ) ;
|
||||
BOOST_CHECK ( opt0 < v1 ) ;
|
||||
BOOST_CHECK ( opt1 > v0 ) ;
|
||||
BOOST_CHECK ( opt1 <= v2 ) ;
|
||||
BOOST_CHECK ( opt1 >= v0 ) ;
|
||||
BOOST_CHECK ( v0 != opt1 ) ;
|
||||
BOOST_CHECK ( v1 == opt2 ) ;
|
||||
BOOST_CHECK ( v0 < opt1 ) ;
|
||||
BOOST_CHECK ( v1 > opt0 ) ;
|
||||
BOOST_CHECK ( v1 <= opt2 ) ;
|
||||
BOOST_CHECK ( v1 >= opt0 ) ;
|
||||
BOOST_CHECK ( def0 != v0 ) ;
|
||||
BOOST_CHECK ( !(def0 == v0) ) ;
|
||||
BOOST_CHECK ( def0 < v0 ) ;
|
||||
BOOST_CHECK ( !(def0 > v0) ) ;
|
||||
BOOST_CHECK ( def0 <= v0 ) ;
|
||||
BOOST_CHECK ( !(def0 >= v0) ) ;
|
||||
BOOST_CHECK ( v0 != def0 ) ;
|
||||
BOOST_CHECK ( !(v0 == def0) ) ;
|
||||
BOOST_CHECK ( !(v0 < def0) ) ;
|
||||
BOOST_CHECK ( v0 > def0 ) ;
|
||||
BOOST_CHECK ( !(v0 <= def0) ) ;
|
||||
BOOST_CHECK ( v0 >= opt0 ) ;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@ -786,7 +664,7 @@ void test_none( T const* )
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
using boost::none ;
|
||||
|
||||
|
||||
optional<T> def0 ;
|
||||
optional<T> def1(none) ;
|
||||
optional<T> non_def( T(1234) ) ;
|
||||
@ -794,10 +672,6 @@ void test_none( T const* )
|
||||
BOOST_CHECK ( def0 == none ) ;
|
||||
BOOST_CHECK ( non_def != none ) ;
|
||||
BOOST_CHECK ( !def1 ) ;
|
||||
BOOST_CHECK ( !(non_def < none) ) ;
|
||||
BOOST_CHECK ( non_def > none ) ;
|
||||
BOOST_CHECK ( !(non_def <= none) ) ;
|
||||
BOOST_CHECK ( non_def >= none ) ;
|
||||
|
||||
non_def = none ;
|
||||
BOOST_CHECK ( !non_def ) ;
|
||||
@ -805,30 +679,11 @@ void test_none( T const* )
|
||||
test_default_implicit_construction(T(1),none);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test_arrow( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
T a(1234);
|
||||
|
||||
optional<T> oa(a) ;
|
||||
optional<T> const coa(a) ;
|
||||
|
||||
BOOST_CHECK ( coa->V() == 1234 ) ;
|
||||
|
||||
oa->V() = 4321 ;
|
||||
|
||||
BOOST_CHECK ( a.V() = 1234 ) ;
|
||||
BOOST_CHECK ( (*oa).V() = 4321 ) ;
|
||||
}
|
||||
|
||||
void test_with_builtin_types()
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
|
||||
test_basics( ARG(double) );
|
||||
test_conditional_ctor_and_get_valur_or( ARG(double) );
|
||||
test_uninitialized_access( ARG(double) );
|
||||
test_no_throwing_swap( ARG(double) );
|
||||
test_relops( ARG(double) ) ;
|
||||
@ -840,7 +695,6 @@ void test_with_class_type()
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
test_basics( ARG(X) );
|
||||
test_conditional_ctor_and_get_valur_or( ARG(X) );
|
||||
test_direct_value_manip( ARG(X) );
|
||||
test_uninitialized_access( ARG(X) );
|
||||
test_throwing_direct_init( ARG(X) );
|
||||
@ -853,7 +707,6 @@ void test_with_class_type()
|
||||
test_throwing_swap( ARG(X) );
|
||||
test_relops( ARG(X) ) ;
|
||||
test_none( ARG(X) ) ;
|
||||
test_arrow( ARG(X) ) ;
|
||||
BOOST_CHECK ( X::count == 0 ) ;
|
||||
}
|
||||
|
||||
@ -910,7 +763,7 @@ void test_conversions1()
|
||||
optional<double> opt3 ;
|
||||
opt3 = opt2 ;
|
||||
BOOST_CHECK(*opt3 == d);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_conversions2()
|
||||
|
@ -93,22 +93,10 @@ class X
|
||||
|
||||
X& operator= ( X const& rhs )
|
||||
{
|
||||
pending_assign = false ;
|
||||
v = rhs.v ;
|
||||
|
||||
if ( throw_on_assign )
|
||||
{
|
||||
TRACE ( "throwing exception in X's assignment" ) ;
|
||||
TRACE ( "X::operator =( X const& rhs). this=" << this << " rhs.v=" << rhs.v ) ;
|
||||
|
||||
v = -1 ;
|
||||
|
||||
throw 0 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = rhs.v ;
|
||||
|
||||
TRACE ( "X::operator =( X const& rhs). this=" << this << " rhs.v=" << rhs.v ) ;
|
||||
}
|
||||
return *this ;
|
||||
}
|
||||
|
||||
@ -127,9 +115,7 @@ class X
|
||||
static int count ;
|
||||
static bool pending_copy ;
|
||||
static bool pending_dtor ;
|
||||
static bool pending_assign ;
|
||||
static bool throw_on_copy ;
|
||||
static bool throw_on_assign ;
|
||||
|
||||
private :
|
||||
|
||||
@ -141,44 +127,32 @@ class X
|
||||
} ;
|
||||
|
||||
|
||||
int X::count = 0 ;
|
||||
bool X::pending_copy = false ;
|
||||
bool X::pending_dtor = false ;
|
||||
bool X::pending_assign = false ;
|
||||
bool X::throw_on_copy = false ;
|
||||
bool X::throw_on_assign = false ;
|
||||
int X::count = 0 ;
|
||||
bool X::pending_copy = false ;
|
||||
bool X::pending_dtor = false ;
|
||||
bool X::throw_on_copy = false ;
|
||||
|
||||
inline void set_pending_copy ( X const* x ) { X::pending_copy = true ; }
|
||||
inline void set_pending_dtor ( X const* x ) { X::pending_dtor = true ; }
|
||||
inline void set_pending_assign ( X const* x ) { X::pending_assign = true ; }
|
||||
inline void set_throw_on_copy ( X const* x ) { X::throw_on_copy = true ; }
|
||||
inline void set_throw_on_assign ( X const* x ) { X::throw_on_assign = true ; }
|
||||
inline void reset_throw_on_copy ( X const* x ) { X::throw_on_copy = false ; }
|
||||
inline void reset_throw_on_assign ( X const* x ) { X::throw_on_assign = false ; }
|
||||
inline void check_is_pending_copy ( X const* x ) { BOOST_CHECK( X::pending_copy ) ; }
|
||||
inline void check_is_pending_dtor ( X const* x ) { BOOST_CHECK( X::pending_dtor ) ; }
|
||||
inline void check_is_pending_assign ( X const* x ) { BOOST_CHECK( X::pending_assign ) ; }
|
||||
inline void check_is_not_pending_copy ( X const* x ) { BOOST_CHECK( !X::pending_copy ) ; }
|
||||
inline void check_is_not_pending_dtor ( X const* x ) { BOOST_CHECK( !X::pending_dtor ) ; }
|
||||
inline void check_is_not_pending_assign( X const* x ) { BOOST_CHECK( !X::pending_assign ) ; }
|
||||
inline void check_instance_count ( int c, X const* x ) { BOOST_CHECK( X::count == c ) ; }
|
||||
inline int get_instance_count ( X const* x ) { return X::count ; }
|
||||
inline void set_pending_copy ( X const* x ) { X::pending_copy = true ; }
|
||||
inline void set_pending_dtor ( X const* x ) { X::pending_dtor = true ; }
|
||||
inline void set_throw_on_copy ( X const* x ) { X::throw_on_copy = true ; }
|
||||
inline void reset_throw_on_copy ( X const* x ) { X::throw_on_copy = false ; }
|
||||
inline void check_is_pending_copy ( X const* x ) { BOOST_CHECK( X::pending_copy ) ; }
|
||||
inline void check_is_pending_dtor ( X const* x ) { BOOST_CHECK( X::pending_dtor ) ; }
|
||||
inline void check_is_not_pending_copy( X const* x ) { BOOST_CHECK( !X::pending_copy ) ; }
|
||||
inline void check_is_not_pending_dtor( X const* x ) { BOOST_CHECK( !X::pending_dtor ) ; }
|
||||
inline void check_instance_count ( int c, X const* x ) { BOOST_CHECK( X::count == c ) ; }
|
||||
inline int get_instance_count ( X const* x ) { return X::count ; }
|
||||
|
||||
inline void set_pending_copy (...) {}
|
||||
inline void set_pending_dtor (...) {}
|
||||
inline void set_pending_assign (...) {}
|
||||
inline void set_throw_on_copy (...) {}
|
||||
inline void set_throw_on_assign (...) {}
|
||||
inline void reset_throw_on_copy (...) {}
|
||||
inline void reset_throw_on_assign (...) {}
|
||||
inline void check_is_pending_copy (...) {}
|
||||
inline void check_is_pending_dtor (...) {}
|
||||
inline void check_is_pending_assign (...) {}
|
||||
inline void check_is_not_pending_copy (...) {}
|
||||
inline void check_is_not_pending_dtor (...) {}
|
||||
inline void check_is_not_pending_assign(...) {}
|
||||
inline void check_instance_count (...) {}
|
||||
inline int get_instance_count (...) { return 0 ; }
|
||||
inline void set_pending_copy (...) {}
|
||||
inline void set_pending_dtor (...) {}
|
||||
inline void set_throw_on_copy (...) {}
|
||||
inline void reset_throw_on_copy (...) {}
|
||||
inline void check_is_pending_copy (...) {}
|
||||
inline void check_is_pending_dtor (...) {}
|
||||
inline void check_is_not_pending_copy(...) {}
|
||||
inline void check_is_not_pending_dtor(...) {}
|
||||
inline void check_instance_count (...) {}
|
||||
inline int get_instance_count (...) { return 0 ; }
|
||||
|
||||
|
||||
template<class T>
|
||||
@ -186,7 +160,7 @@ inline void check_uninitialized_const ( optional<T> const& opt )
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_NO_NULL_COMPARE
|
||||
BOOST_CHECK( opt == 0 ) ;
|
||||
#endif
|
||||
#endif
|
||||
BOOST_CHECK( !opt ) ;
|
||||
BOOST_CHECK( !get_pointer(opt) ) ;
|
||||
BOOST_CHECK( !opt.get_ptr() ) ;
|
||||
|
@ -13,16 +13,14 @@
|
||||
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
struct A {} ;
|
||||
struct B {} ;
|
||||
//
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
//
|
||||
void test_no_unsupported_conversion()
|
||||
{
|
||||
boost::optional<A> opt1;
|
||||
boost::optional<B> opt2;
|
||||
opt2 = opt1 ; // Cannot convert from "A" to "B"
|
||||
boost::optional<int> opt1(1) ;
|
||||
boost::optional< std::string > opt2 ;
|
||||
opt2 = opt1 ; // Cannot convert from "int" to "std::string"
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,89 +0,0 @@
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
#include<stdexcept>
|
||||
#include<string>
|
||||
#include<sstream>
|
||||
|
||||
#define BOOST_ENABLE_ASSERT_HANDLER
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
#include "boost/optional/optional_io.hpp"
|
||||
#include "boost/none.hpp"
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
#ifdef ENABLE_TRACE
|
||||
#define TRACE(msg) std::cout << msg << std::endl ;
|
||||
#else
|
||||
#define TRACE(msg)
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
void assertion_failed (char const * expr, char const * func, char const * file, long )
|
||||
{
|
||||
using std::string ;
|
||||
string msg = string("Boost assertion failure for \"")
|
||||
+ string(expr)
|
||||
+ string("\" at file \"")
|
||||
+ string(file)
|
||||
+ string("\" function \"")
|
||||
+ string(func)
|
||||
+ string("\"") ;
|
||||
|
||||
TRACE(msg);
|
||||
|
||||
throw std::logic_error(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using namespace std ;
|
||||
using namespace boost ;
|
||||
|
||||
template<class Opt>
|
||||
void test2( Opt o, Opt buff )
|
||||
{
|
||||
stringstream s ;
|
||||
|
||||
s << o ;
|
||||
s >> buff ;
|
||||
|
||||
BOOST_ASSERT( buff == o ) ;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void test( T v, T w )
|
||||
{
|
||||
test2( make_optional(v), optional<T> ());
|
||||
test2( make_optional(v), make_optional(w));
|
||||
test2( optional<T> () , optional<T> ());
|
||||
test2( optional<T> () , make_optional(w));
|
||||
}
|
||||
|
||||
int test_main( int, char* [] )
|
||||
{
|
||||
try
|
||||
{
|
||||
test(1,2);
|
||||
test(string("hello"),string("buffer"));
|
||||
test(string(""),string("buffer"));
|
||||
}
|
||||
catch ( ... )
|
||||
{
|
||||
BOOST_ERROR("Unexpected Exception caught!");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ inline void check_ref_uninitialized_const ( optional<T&> const& opt )
|
||||
{
|
||||
#ifndef BOOST_OPTIONAL_NO_NULL_COMPARE
|
||||
BOOST_CHECK( opt == 0 ) ;
|
||||
#endif
|
||||
#endif
|
||||
BOOST_CHECK( !opt ) ;
|
||||
}
|
||||
template<class T>
|
||||
@ -104,16 +104,9 @@ void test_basics( T const* )
|
||||
|
||||
T z(0);
|
||||
|
||||
T original_a(1);
|
||||
|
||||
T a(1);
|
||||
|
||||
T b(2);
|
||||
|
||||
T c(10);
|
||||
|
||||
T& aref = a ;
|
||||
T& bref = b ;
|
||||
|
||||
// Default construction.
|
||||
// 'def' state is Uninitialized.
|
||||
@ -122,16 +115,13 @@ void test_basics( T const* )
|
||||
check_ref_uninitialized(def);
|
||||
|
||||
// Direct initialization.
|
||||
// 'oa' state is Initialized and binds to 'a'
|
||||
// 'oa' state is Initialized with 'a'
|
||||
// T::T( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
optional<T&> oa ( aref ) ;
|
||||
check_is_pending_copy( ARG(T) );
|
||||
check_ref_initialized(oa);
|
||||
check_ref_value(oa,a,z);
|
||||
*oa = b ; // changes the value of 'a' through the reference
|
||||
BOOST_CHECK( a == b ) ;
|
||||
|
||||
|
||||
// Copy initialization.
|
||||
// T::T ( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
@ -140,32 +130,27 @@ void test_basics( T const* )
|
||||
check_is_pending_copy( ARG(T) ) ;
|
||||
check_ref_initialized_const(oa2);
|
||||
check_ref_value_const(oa2,a,z);
|
||||
*oa2 = original_a ; // restores the value of 'a' through the reference
|
||||
BOOST_CHECK( a == original_a ) ;
|
||||
|
||||
T b(2);
|
||||
optional<T&> ob ;
|
||||
|
||||
// Value-Assignment upon Uninitialized optional.
|
||||
// T::T ( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
ob = a ; // Binds ob to a temporary non-const refererence to 'a'
|
||||
ob = a ;
|
||||
check_is_pending_copy( ARG(T) ) ;
|
||||
check_ref_initialized(ob);
|
||||
check_ref_value(ob,a,z);
|
||||
a = c;
|
||||
check_ref_value(ob,a,z);
|
||||
|
||||
// Value-Assignment upon Initialized optional.
|
||||
// T::operator= ( T const& x ) is used.
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
ob = b ; // Rebinds 'ob' to 'b' (without changing 'a')
|
||||
check_is_pending_assign( ARG(T) ) ;
|
||||
// T::T ( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
ob = b ;
|
||||
check_is_pending_dtor( ARG(T) ) ;
|
||||
check_is_pending_copy( ARG(T) ) ;
|
||||
check_ref_initialized(ob);
|
||||
check_ref_value(ob,b,z);
|
||||
BOOST_CHECK(a == c); // From a=c in previous test
|
||||
b = c;
|
||||
check_ref_value(ob,b,z);
|
||||
|
||||
|
||||
// Assignment initialization.
|
||||
// T::T ( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
@ -177,12 +162,14 @@ void test_basics( T const* )
|
||||
|
||||
|
||||
// Assignment
|
||||
// T::operator=( T const& x ) is used.
|
||||
set_pending_assign( ARG(T) ) ;
|
||||
oa = ob ; // Rebinds 'a' to 'b'
|
||||
check_is_pending_assign( ARG(T) ) ;
|
||||
// T::~T() is used to destroy previous value in ob.
|
||||
// T::T ( T const& x ) is NOT used becasue the optional holds a reference.
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
set_pending_copy( ARG(T) ) ;
|
||||
oa = ob ;
|
||||
check_is_pending_dtor( ARG(T) ) ;
|
||||
check_is_pending_copy( ARG(T) ) ;
|
||||
check_ref_initialized(oa);
|
||||
a = original_a ;
|
||||
check_ref_value(oa,b,z);
|
||||
|
||||
// Uninitializing Assignment upon Initialized Optional
|
||||
@ -203,7 +190,6 @@ void test_basics( T const* )
|
||||
check_is_pending_copy( ARG(T) ) ;
|
||||
check_ref_uninitialized(oa);
|
||||
|
||||
|
||||
// Deinitialization of Initialized Optional
|
||||
// T::~T() is NOT used becasue the optional holds a reference.
|
||||
set_pending_dtor( ARG(T) ) ;
|
||||
@ -226,9 +212,9 @@ template<class T>
|
||||
void test_relops( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
|
||||
reset_throw_on_copy( ARG(T) ) ;
|
||||
|
||||
|
||||
T v0(18);
|
||||
T v1(19);
|
||||
T v2(19);
|
||||
@ -247,11 +233,11 @@ void test_relops( T const* )
|
||||
|
||||
// Check when both are uininitalized.
|
||||
BOOST_CHECK ( def0 == def1 ) ; // both uninitialized compare equal
|
||||
BOOST_CHECK ( !(def0 < def1) ) ; // uninitialized is never less than uninitialized
|
||||
BOOST_CHECK ( !(def0 > def1) ) ; // uninitialized is never greater than uninitialized
|
||||
BOOST_CHECK ( !(def0 < def1) ) ; // uninitialized is never less than uninitialized
|
||||
BOOST_CHECK ( !(def0 > def1) ) ; // uninitialized is never greater than uninitialized
|
||||
BOOST_CHECK ( !(def0 != def1) ) ;
|
||||
BOOST_CHECK ( def0 <= def1 ) ;
|
||||
BOOST_CHECK ( def0 >= def1 ) ;
|
||||
BOOST_CHECK ( def0 <= def1 ) ;
|
||||
BOOST_CHECK ( def0 >= def1 ) ;
|
||||
|
||||
// Check when only lhs is uninitialized.
|
||||
BOOST_CHECK ( def0 != opt0 ) ; // uninitialized is never equal to initialized
|
||||
@ -268,7 +254,7 @@ void test_relops( T const* )
|
||||
BOOST_CHECK ( opt0 > def0 ) ;
|
||||
BOOST_CHECK ( !(opt0 <= def0) ) ;
|
||||
BOOST_CHECK ( opt0 >= opt0 ) ;
|
||||
|
||||
|
||||
// If both are initialized, values are compared
|
||||
BOOST_CHECK ( opt0 != opt1 ) ;
|
||||
BOOST_CHECK ( opt1 == opt2 ) ;
|
||||
@ -284,7 +270,7 @@ void test_none( T const* )
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
using boost::none ;
|
||||
|
||||
|
||||
T a(1234);
|
||||
|
||||
optional<T&> def0 ;
|
||||
@ -299,23 +285,6 @@ void test_none( T const* )
|
||||
BOOST_CHECK ( !non_def ) ;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test_arrow( T const* )
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
|
||||
T a(1234);
|
||||
|
||||
optional<T&> oa(a) ;
|
||||
optional<T&> const coa(a) ;
|
||||
|
||||
BOOST_CHECK ( coa->V() == 1234 ) ;
|
||||
|
||||
oa->V() = 4321 ;
|
||||
|
||||
BOOST_CHECK ( a.V() = 4321 ) ;
|
||||
}
|
||||
|
||||
void test_with_builtin_types()
|
||||
{
|
||||
TRACE( std::endl << BOOST_CURRENT_FUNCTION );
|
||||
@ -332,7 +301,6 @@ void test_with_class_type()
|
||||
test_basics( ARG(X) );
|
||||
test_relops( ARG(X) ) ;
|
||||
test_none ( ARG(X) ) ;
|
||||
test_arrow ( ARG(X) ) ;
|
||||
|
||||
BOOST_CHECK ( X::count == 0 ) ;
|
||||
}
|
||||
|
23
test/optional_test_ref_fail2.cpp
Normal file
23
test/optional_test_ref_fail2.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// fernando_cacciola@hotmail.com
|
||||
//
|
||||
#include "boost/optional.hpp"
|
||||
|
||||
//
|
||||
// THIS TEST SHOULD FAIL TO COMPILE
|
||||
//
|
||||
void optional_reference__test_no_ptr_access()
|
||||
{
|
||||
boost::optional<int&> opt ;
|
||||
opt.get_ptr();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user