From 979a10174f86db3384455eadce6f37d694503343 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Tue, 23 May 2017 14:57:21 +0200 Subject: [PATCH] Conditionally provide interfaces based on deprecated/removed std::auto_ptr and/or std::unique_ptr, and replace C++98 function adapters by inline typedefs. Signed-off-by: Daniela Engert --- .../detail/associative_ptr_container.hpp | 18 ++++ .../detail/reversible_ptr_container.hpp | 113 +++++++++++++++++++-- include/boost/ptr_container/ptr_array.hpp | 58 ++++++++++- .../boost/ptr_container/ptr_circular_buffer.hpp | 36 +++++++ include/boost/ptr_container/ptr_inserter.hpp | 41 ++++++++ include/boost/ptr_container/ptr_map_adapter.hpp | 94 +++++++++++++++++ .../boost/ptr_container/ptr_sequence_adapter.hpp | 36 +++++++ include/boost/ptr_container/ptr_set_adapter.hpp | 88 ++++++++++++++++ test/associative_test_data.hpp | 15 ++- test/ptr_array.cpp | 10 ++ test/ptr_deque.cpp | 13 ++- test/ptr_list.cpp | 27 +++-- test/ptr_map.cpp | 14 +++ test/ptr_map_adapter.cpp | 5 + test/ptr_set.cpp | 11 ++ test/ptr_unordered_map.cpp | 14 +++ test/ptr_unordered_set.cpp | 11 ++ test/sequence_test_data.hpp | 34 ++++++- test/test_data.hpp | 8 ++ test/tut1.cpp | 10 +- test/view_example.cpp | 18 +++- 21 files changed, 639 insertions(+), 35 deletions(-) diff --git a/include/boost/ptr_container/detail/associative_ptr_container.hpp b/include/boost/ptr_container/detail/associative_ptr_container.hpp index 56854e79..223e495c 100644 --- a/include/boost/ptr_container/detail/associative_ptr_container.hpp +++ b/include/boost/ptr_container/detail/associative_ptr_container.hpp @@ -103,10 +103,18 @@ namespace ptr_container_detail : base_type( first, last, hash, pred, a ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit associative_ptr_container( std::auto_ptr r ) : base_type( r ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit associative_ptr_container( std::unique_ptr r ) + : base_type( std::move( r ) ) + { } +#endif associative_ptr_container( const associative_ptr_container& r ) : base_type( r.begin(), r.end(), container_type() ) @@ -117,12 +125,22 @@ namespace ptr_container_detail : base_type( r.begin(), r.end(), container_type() ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > associative_ptr_container& operator=( std::auto_ptr r ) // nothrow { base_type::operator=( r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + associative_ptr_container& operator=( std::unique_ptr r ) // nothrow + { + base_type::operator=( std::move( r ) ); + return *this; + } +#endif associative_ptr_container& operator=( associative_ptr_container r ) // strong { diff --git a/include/boost/ptr_container/detail/reversible_ptr_container.hpp b/include/boost/ptr_container/detail/reversible_ptr_container.hpp index fe36390b..a342b68a 100644 --- a/include/boost/ptr_container/detail/reversible_ptr_container.hpp +++ b/include/boost/ptr_container/detail/reversible_ptr_container.hpp @@ -39,6 +39,14 @@ #include #include +#ifndef BOOST_PTR_CONTAINER_NO_AUTO_PTR +# ifdef BOOST_NO_AUTO_PTR +# define BOOST_PTR_CONTAINER_NO_AUTO_PTR 1 +# else +# define BOOST_PTR_CONTAINER_NO_AUTO_PTR 0 +# endif +#endif + #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) #pragma warning(push) #pragma warning(disable:4127) @@ -345,12 +353,21 @@ namespace ptr_container_detail explicit reversible_ptr_container( const allocator_type& a ) : c_( a ) { } - + +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit reversible_ptr_container( std::auto_ptr clone ) { swap( *clone ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit reversible_ptr_container( std::unique_ptr clone ) + { + swap( *clone ); + } +#endif reversible_ptr_container( const reversible_ptr_container& r ) { @@ -363,12 +380,22 @@ namespace ptr_container_detail constructor_impl( r.begin(), r.end(), std::forward_iterator_tag() ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > reversible_ptr_container& operator=( std::auto_ptr clone ) // nothrow { swap( *clone ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + reversible_ptr_container& operator=( std::unique_ptr clone ) // nothrow + { + swap( *clone ); + return *this; + } +#endif reversible_ptr_container& operator=( reversible_ptr_container r ) // strong { @@ -588,11 +615,20 @@ namespace ptr_container_detail return res; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator before, std::auto_ptr x ) { return insert( before, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator before, std::unique_ptr x ) + { + return insert( before, x.release() ); + } +#endif iterator erase( iterator x ) // nothrow { @@ -650,11 +686,20 @@ namespace ptr_container_detail return boost::ptr_container_detail::move( old ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > auto_type replace( iterator where, std::auto_ptr x ) { return replace( where, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + auto_type replace( iterator where, std::unique_ptr x ) + { + return replace( where, x.release() ); + } +#endif auto_type replace( size_type idx, Ty_* x ) // strong { @@ -669,11 +714,20 @@ namespace ptr_container_detail return boost::ptr_container_detail::move( old ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > auto_type replace( size_type idx, std::auto_ptr x ) { return replace( idx, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + auto_type replace( size_type idx, std::unique_ptr x ) + { + return replace( idx, x.release() ); + } +#endif }; // 'reversible_ptr_container' @@ -689,12 +743,9 @@ namespace ptr_container_detail #define BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \ using base_type::release; #endif - - // - // two-phase lookup of template functions - // is buggy on most compilers, so we use a macro instead - // -#define BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type ) \ + +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR +#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) \ explicit PC( std::auto_ptr r ) \ : base_type ( r ) { } \ \ @@ -702,20 +753,64 @@ namespace ptr_container_detail { \ base_type::operator=( r ); \ return *this; \ - } \ + } +#else +#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) +#endif + +#ifndef BOOST_NO_CXX11_SMART_PTR +#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type ) \ + explicit PC( std::unique_ptr r ) \ + : base_type ( std::move( r ) ) { } \ \ + PC& operator=( std::unique_ptr r ) \ + { \ + base_type::operator=( std::move( r ) ); \ + return *this; \ + } +#else +#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type ) +#endif + +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR +#define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \ std::auto_ptr release() \ { \ std::auto_ptr ptr( new this_type );\ this->swap( *ptr ); \ return ptr; \ } \ - BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \ \ std::auto_ptr clone() const \ { \ return std::auto_ptr( new this_type( this->begin(), this->end() ) ); \ } +#elif !defined( BOOST_NO_CXX11_SMART_PTR ) +#define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \ + std::unique_ptr release() \ + { \ + std::unique_ptr ptr( new this_type );\ + this->swap( *ptr ); \ + return ptr; \ + } \ + \ + std::unique_ptr clone() const \ + { \ + return std::unique_ptr( new this_type( this->begin(), this->end() ) ); \ + } +#else +#define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) +#endif + + // + // two-phase lookup of template functions + // is buggy on most compilers, so we use a macro instead + // +#define BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type ) \ + BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) \ + BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type ) \ + BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \ + BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) #define BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( PC, base_type ) \ \ diff --git a/include/boost/ptr_container/ptr_array.hpp b/include/boost/ptr_container/ptr_array.hpp index bfff8af6..584d06e0 100644 --- a/include/boost/ptr_container/ptr_array.hpp +++ b/include/boost/ptr_container/ptr_array.hpp @@ -102,8 +102,14 @@ namespace boost static_cast( &r[i] ) ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR explicit ptr_array( std::auto_ptr r ) : base_class( r ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + explicit ptr_array( std::unique_ptr r ) + : base_class( std::move( r ) ) { } +#endif ptr_array& operator=( ptr_array r ) { @@ -111,12 +117,22 @@ namespace boost return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR ptr_array& operator=( std::auto_ptr r ) { base_class::operator=(r); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + ptr_array& operator=( std::unique_ptr r ) + { + base_class::operator=(std::move(r)); + return *this; + } +#endif +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR std::auto_ptr release() { std::auto_ptr ptr( new this_type ); @@ -127,12 +143,32 @@ namespace boost std::auto_ptr clone() const { std::auto_ptr pa( new this_type ); + clone_array_elements( *pa ); + return pa; + } +#elif !defined(BOOST_NO_CXX11_SMART_PTR) + std::unique_ptr release() + { + std::unique_ptr ptr( new this_type ); + this->swap( *ptr ); + return ptr; + } + + std::unique_ptr clone() const + { + std::unique_ptr pa( new this_type ); + clone_array_elements( *pa ); + return pa; + } +#endif + private: + void clone_array_elements( this_type &pa ) const + { for( size_t i = 0; i != N; ++i ) { if( !this->is_null(i) ) - pa->replace( i, pa->null_policy_allocate_clone( &(*this)[i] ) ); + pa.replace( i, pa.null_policy_allocate_clone( &(*this)[i] ) ); } - return pa; } private: // hide some members @@ -158,11 +194,20 @@ namespace boost return boost::ptr_container::move(res); // nothrow } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< size_t idx, class V > auto_type replace( std::auto_ptr r ) { return replace( r.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< size_t idx, class V > + auto_type replace( std::unique_ptr r ) + { + return replace( r.release() ); + } +#endif auto_type replace( size_t idx, U* r ) // strong { @@ -177,11 +222,20 @@ namespace boost return boost::ptr_container::move(res); // nothrow } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class V > auto_type replace( size_t idx, std::auto_ptr r ) { return replace( idx, r.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class V > + auto_type replace( size_t idx, std::unique_ptr r ) + { + return replace( idx, r.release() ); + } +#endif using base_class::at; diff --git a/include/boost/ptr_container/ptr_circular_buffer.hpp b/include/boost/ptr_container/ptr_circular_buffer.hpp index 9acf8412..09db2f06 100644 --- a/include/boost/ptr_container/ptr_circular_buffer.hpp +++ b/include/boost/ptr_container/ptr_circular_buffer.hpp @@ -294,11 +294,20 @@ namespace boost this->base().push_back( ptr ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > void push_back( std::auto_ptr ptr ) // nothrow { push_back( ptr.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + void push_back( std::unique_ptr ptr ) // nothrow + { + push_back( ptr.release() ); + } +#endif void push_front( value_type ptr ) // nothrow { @@ -311,11 +320,20 @@ namespace boost this->base().push_front( ptr ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > void push_front( std::auto_ptr ptr ) // nothrow { push_front( ptr.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + void push_front( std::unique_ptr ptr ) // nothrow + { + push_front( ptr.release() ); + } +#endif iterator insert( iterator pos, value_type ptr ) // nothrow { @@ -335,11 +353,20 @@ namespace boost return this->base().insert( pos.base(), ptr ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator pos, std::auto_ptr ptr ) // nothrow { return insert( pos, ptr.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator pos, std::unique_ptr ptr ) // nothrow + { + return insert( pos, ptr.release() ); + } +#endif template< class InputIterator > void insert( iterator pos, InputIterator first, InputIterator last ) // basic @@ -378,11 +405,20 @@ namespace boost return this->base().rinsert( pos.base(), ptr ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator rinsert( iterator pos, std::auto_ptr ptr ) // nothrow { return rinsert( pos, ptr.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator rinsert( iterator pos, std::unique_ptr ptr ) // nothrow + { + return rinsert( pos, ptr.release() ); + } +#endif template< class InputIterator > diff --git a/include/boost/ptr_container/ptr_inserter.hpp b/include/boost/ptr_container/ptr_inserter.hpp index d76c018e..10eced72 100644 --- a/include/boost/ptr_container/ptr_inserter.hpp +++ b/include/boost/ptr_container/ptr_inserter.hpp @@ -20,6 +20,14 @@ #include #include +#ifndef BOOST_PTR_CONTAINER_NO_AUTO_PTR +# ifdef BOOST_NO_AUTO_PTR +# define BOOST_PTR_CONTAINER_NO_AUTO_PTR 1 +# else +# define BOOST_PTR_CONTAINER_NO_AUTO_PTR 0 +# endif +#endif + namespace boost { namespace ptr_container @@ -71,6 +79,7 @@ namespace ptr_container return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class T > ptr_back_insert_iterator& operator=( std::auto_ptr r ) @@ -78,6 +87,16 @@ namespace ptr_container container->push_back( r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class T > + ptr_back_insert_iterator& + operator=( std::unique_ptr r ) + { + container->push_back( std::move( r ) ); + return *this; + } +#endif ptr_back_insert_iterator& operator=( typename PtrContainer::const_reference r ) @@ -128,6 +147,7 @@ namespace ptr_container return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class T > ptr_front_insert_iterator& operator=( std::auto_ptr r ) @@ -135,6 +155,16 @@ namespace ptr_container container->push_front( r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class T > + ptr_front_insert_iterator& + operator=( std::unique_ptr r ) + { + container->push_front( std::move( r ) ); + return *this; + } +#endif ptr_front_insert_iterator& operator=( typename PtrContainer::const_reference r ) @@ -187,6 +217,7 @@ namespace ptr_container return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class T > ptr_insert_iterator& operator=( std::auto_ptr r ) @@ -194,6 +225,16 @@ namespace ptr_container iter = container->insert( iter, r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class T > + ptr_insert_iterator& + operator=( std::unique_ptr r ) + { + iter = container->insert( iter, std::move( r ) ); + return *this; + } +#endif ptr_insert_iterator& operator=( typename PtrContainer::const_reference r ) diff --git a/include/boost/ptr_container/ptr_map_adapter.hpp b/include/boost/ptr_container/ptr_map_adapter.hpp index 5ffc0f47..7fac7ef4 100644 --- a/include/boost/ptr_container/ptr_map_adapter.hpp +++ b/include/boost/ptr_container/ptr_map_adapter.hpp @@ -261,6 +261,7 @@ namespace ptr_container_detail : base_type( first, last, hash, pred, a ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit ptr_map_adapter_base( std::auto_ptr clone ) : base_type( clone ) @@ -272,6 +273,20 @@ namespace ptr_container_detail base_type::operator=( clone ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit ptr_map_adapter_base( std::unique_ptr clone ) + : base_type( clone ) + { } + + template< typename PtrContainer > + ptr_map_adapter_base& operator=( std::unique_ptr clone ) + { + base_type::operator=( std::move( clone ) ); + return *this; + } +#endif iterator find( const key_type& x ) { @@ -355,11 +370,20 @@ namespace ptr_container_detail return boost::ptr_container::move( old ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > auto_type replace( iterator where, std::auto_ptr x ) { return replace( where, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + auto_type replace( iterator where, std::unique_ptr x ) + { + return replace( where, x.release() ); + } +#endif protected: size_type bucket( const key_type& key ) const @@ -490,9 +514,16 @@ namespace ptr_container_detail map_basic_clone_and_insert( r.begin(), r.end() ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > ptr_map_adapter( std::auto_ptr r ) : base_type( r ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + ptr_map_adapter( std::unique_ptr r ) : base_type( std::move( r ) ) + { } +#endif ptr_map_adapter& operator=( ptr_map_adapter r ) { @@ -500,12 +531,22 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > ptr_map_adapter& operator=( std::auto_ptr r ) { base_type::operator=( r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + ptr_map_adapter& operator=( std::unique_ptr r ) + { + base_type::operator=( std::move( r ) ); + return *this; + } +#endif using base_type::release; @@ -554,11 +595,20 @@ namespace ptr_container_detail return insert_impl( key, x ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > std::pair insert( const key_type& key, std::auto_ptr x ) { return insert_impl( key, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + std::pair insert( const key_type& key, std::unique_ptr x ) + { + return insert_impl( key, x.release() ); + } +#endif template< class F, class S > iterator insert( iterator before, ptr_container_detail::ref_pair p ) // strong @@ -581,11 +631,20 @@ namespace ptr_container_detail return insert_impl( before, key, x ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator before, const key_type& key, std::auto_ptr x ) // strong { return insert_impl( before, key, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator before, const key_type& key, std::unique_ptr x ) // strong + { + return insert_impl( before, key, x.release() ); + } +#endif template< class PtrMapAdapter > bool transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator object, @@ -740,9 +799,16 @@ namespace ptr_container_detail map_basic_clone_and_insert( r.begin(), r.end() ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > explicit ptr_multimap_adapter( std::auto_ptr r ) : base_type( r ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + explicit ptr_multimap_adapter( std::unique_ptr r ) : base_type( std::move( r ) ) + { } +#endif ptr_multimap_adapter& operator=( ptr_multimap_adapter r ) { @@ -750,12 +816,22 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > ptr_multimap_adapter& operator=( std::auto_ptr r ) { base_type::operator=( r ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + ptr_multimap_adapter& operator=( std::unique_ptr r ) + { + base_type::operator=( std::move( r ) ); + return *this; + } +#endif using base_type::release; @@ -805,11 +881,20 @@ namespace ptr_container_detail return insert_impl( key, x ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( const key_type& key, std::auto_ptr x ) { return insert_impl( key, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( const key_type& key, std::unique_ptr x ) + { + return insert_impl( key, x.release() ); + } +#endif template< class F, class S > iterator insert( iterator before, ptr_container_detail::ref_pair p ) // strong @@ -826,11 +911,20 @@ namespace ptr_container_detail return insert_impl( before, key, x ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator before, const key_type& key, std::auto_ptr x ) // strong { return insert_impl( before, key, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator before, const key_type& key, std::unique_ptr x ) // strong + { + return insert_impl( before, key, x.release() ); + } +#endif template< class PtrMapAdapter > void transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator object, diff --git a/include/boost/ptr_container/ptr_sequence_adapter.hpp b/include/boost/ptr_container/ptr_sequence_adapter.hpp index ad8542ed..221139cf 100644 --- a/include/boost/ptr_container/ptr_sequence_adapter.hpp +++ b/include/boost/ptr_container/ptr_sequence_adapter.hpp @@ -219,10 +219,18 @@ namespace ptr_container_detail : base_type( r, tag ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit ptr_sequence_adapter( std::auto_ptr clone ) : base_type( clone ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit ptr_sequence_adapter( std::unique_ptr clone ) + : base_type( std::move( clone ) ) + { } +#endif ptr_sequence_adapter& operator=( const ptr_sequence_adapter r ) { @@ -230,12 +238,22 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > ptr_sequence_adapter& operator=( std::auto_ptr clone ) { base_type::operator=( clone ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + ptr_sequence_adapter& operator=( std::unique_ptr clone ) + { + base_type::operator=( std::move( clone ) ); + return *this; + } +#endif ///////////////////////////////////////////////////////////// // modifiers @@ -249,11 +267,20 @@ namespace ptr_container_detail ptr.release(); // nothrow } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > void push_back( std::auto_ptr x ) { push_back( x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + void push_back( std::unique_ptr x ) + { + push_back( x.release() ); + } +#endif void push_front( value_type x ) { @@ -263,11 +290,20 @@ namespace ptr_container_detail ptr.release(); // nothrow } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > void push_front( std::auto_ptr x ) { push_front( x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + void push_front( std::unique_ptr x ) + { + push_front( x.release() ); + } +#endif auto_type pop_back() { diff --git a/include/boost/ptr_container/ptr_set_adapter.hpp b/include/boost/ptr_container/ptr_set_adapter.hpp index 9c035952..dc3b50f9 100644 --- a/include/boost/ptr_container/ptr_set_adapter.hpp +++ b/include/boost/ptr_container/ptr_set_adapter.hpp @@ -182,10 +182,18 @@ namespace ptr_container_detail : base_type( r ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit ptr_set_adapter_base( std::auto_ptr clone ) : base_type( clone ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit ptr_set_adapter_base( std::unique_ptr clone ) + : base_type( std::move( clone ) ) + { } +#endif ptr_set_adapter_base& operator=( ptr_set_adapter_base r ) { @@ -193,12 +201,22 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< typename PtrContainer > ptr_set_adapter_base& operator=( std::auto_ptr clone ) { base_type::operator=( clone ); return *this; } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< typename PtrContainer > + ptr_set_adapter_base& operator=( std::unique_ptr clone ) + { + base_type::operator=( std::move( clone ) ); + return *this; + } +#endif using base_type::erase; @@ -393,10 +411,18 @@ namespace ptr_container_detail : base_type( r ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit ptr_set_adapter( std::auto_ptr clone ) : base_type( clone ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit ptr_set_adapter( std::unique_ptr clone ) + : base_type( std::move( clone ) ) + { } +#endif template< class U, class Set, class CA, bool b > ptr_set_adapter& operator=( const ptr_set_adapter& r ) @@ -405,11 +431,20 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class T > void operator=( std::auto_ptr r ) { base_type::operator=( r ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class T > + void operator=( std::unique_ptr r ) + { + base_type::operator=( std::move( r ) ); + } +#endif std::pair insert( key_type* x ) // strong { @@ -423,11 +458,20 @@ namespace ptr_container_detail return std::make_pair( iterator( res.first ), res.second ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > std::pair insert( std::auto_ptr x ) { return insert( x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + std::pair insert( std::unique_ptr x ) + { + return insert( x.release() ); + } +#endif iterator insert( iterator where, key_type* x ) // strong @@ -442,11 +486,20 @@ namespace ptr_container_detail return iterator( res); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator where, std::auto_ptr x ) { return insert( where, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator where, std::unique_ptr x ) + { + return insert( where, x.release() ); + } +#endif template< typename InputIterator > void insert( InputIterator first, InputIterator last ) // basic @@ -593,10 +646,18 @@ namespace ptr_container_detail : base_type( r ) { } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class PtrContainer > explicit ptr_multiset_adapter( std::auto_ptr clone ) : base_type( clone ) { } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class PtrContainer > + explicit ptr_multiset_adapter( std::unique_ptr clone ) + : base_type( std::move( clone ) ) + { } +#endif template< class U, class Set, class CA, bool b > ptr_multiset_adapter& operator=( const ptr_multiset_adapter& r ) @@ -605,22 +666,40 @@ namespace ptr_container_detail return *this; } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class T > void operator=( std::auto_ptr r ) { base_type::operator=( r ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class T > + void operator=( std::unique_ptr r ) + { + base_type::operator=( std::move( r ) ); + } +#endif iterator insert( iterator before, key_type* x ) // strong { return base_type::insert( before, x ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( iterator before, std::auto_ptr x ) { return insert( before, x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( iterator before, std::unique_ptr x ) + { + return insert( before, x.release() ); + } +#endif iterator insert( key_type* x ) // strong { @@ -633,11 +712,20 @@ namespace ptr_container_detail return iterator( res ); } +#if !BOOST_PTR_CONTAINER_NO_AUTO_PTR template< class U > iterator insert( std::auto_ptr x ) { return insert( x.release() ); } +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + template< class U > + iterator insert( std::unique_ptr x ) + { + return insert( x.release() ); + } +#endif template< typename InputIterator > void insert( InputIterator first, InputIterator last ) // basic diff --git a/test/associative_test_data.hpp b/test/associative_test_data.hpp index b689fe29..eba494f8 100644 --- a/test/associative_test_data.hpp +++ b/test/associative_test_data.hpp @@ -100,10 +100,17 @@ void ptr_set_test() T* t = new T; c.insert( c.end(), t ); - c.insert( c.end(), std::auto_ptr( new T ) ); c.insert( new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR + c.insert( c.end(), std::auto_ptr( new T ) ); std::auto_ptr ap( new T ); c.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( c.end(), std::unique_ptr( new T ) ); + std::unique_ptr up( new T ); + c.insert( std::move( up ) ); +#endif c3.insert( c.begin(), c.end() ); c.erase( c.begin() ); c3.erase( c3.begin(), c3.end() ); @@ -130,7 +137,11 @@ void ptr_set_test() c.insert( c.end(), new T ); typename C::auto_type ptr2 = c.release( c.begin() ); - std::auto_ptr ap2 = c.release(); +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + std::unique_ptr up2 = c.release(); +#elif !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR + std::auto_ptr ap2 = c.release(); +#endif c = c2.clone(); BOOST_TEST_MESSAGE( "finished release/clone test" ); diff --git a/test/ptr_array.cpp b/test/ptr_array.cpp index ea12db25..03db64a0 100644 --- a/test/ptr_array.cpp +++ b/test/ptr_array.cpp @@ -89,7 +89,12 @@ void test_array() ptr_array vec; BOOST_CHECK_THROW( vec.at(10), bad_ptr_container_operation ); BOOST_CHECK_THROW( (vec.replace(10u, new int(0))), bad_ptr_container_operation ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR BOOST_CHECK_THROW( (vec.replace(10u, std::auto_ptr(new int(0)))), bad_ptr_container_operation ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_CHECK_THROW( (vec.replace(10u, std::unique_ptr(new int(0)))), bad_ptr_container_operation ); +#endif BOOST_CHECK_THROW( (vec.replace(0u, 0)), bad_ptr_container_operation ); ptr_array derived; @@ -112,7 +117,12 @@ void test_array_interface() c.replace( 0, new T ); c.replace( 1, new B ); c.replace( 9, new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c.replace( 0, std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.replace( 0, std::unique_ptr( new T ) ); +#endif const C c2( c.clone() ); BOOST_DEDUCED_TYPENAME C::iterator i = c.begin(); diff --git a/test/ptr_deque.cpp b/test/ptr_deque.cpp index d76e555d..d9c75f05 100755 --- a/test/ptr_deque.cpp +++ b/test/ptr_deque.cpp @@ -37,9 +37,18 @@ void test_ptr_deque() random_access_algorithms_test< ptr_deque >(); ptr_deque di; di.push_front( new int(0) ); - BOOST_CHECK_EQUAL( di.size(), 1u ); + std::size_t size = 1u; + BOOST_CHECK_EQUAL( di.size(), size ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR di.push_front( std::auto_ptr( new int(1) ) ); - BOOST_CHECK_EQUAL( di.size(), 2u ); + ++size; + BOOST_CHECK_EQUAL( di.size(), size ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + di.push_front( std::unique_ptr( new int(2) ) ); + ++size; + BOOST_CHECK_EQUAL( di.size(), size ); +#endif } using boost::unit_test::test_suite; diff --git a/test/ptr_list.cpp b/test/ptr_list.cpp index 3961c66f..cc68e68d 100644 --- a/test/ptr_list.cpp +++ b/test/ptr_list.cpp @@ -11,40 +11,45 @@ #define PTR_LIST_TEST 1 #define PTR_CONTAINER_DEBUG 0 - + #include #include "sequence_test_data.hpp" #include void test_list() { - + reversible_container_test< ptr_list, Base, Derived_class >(); reversible_container_test< ptr_list, Value, Value >(); reversible_container_test< ptr_list< nullable >, Base, Derived_class >(); reversible_container_test< ptr_list< nullable >, Value, Value >(); - container_assignment_test< ptr_list, ptr_list, + container_assignment_test< ptr_list, ptr_list, Derived_class>(); - container_assignment_test< ptr_list< nullable >, - ptr_list< nullable >, + container_assignment_test< ptr_list< nullable >, + ptr_list< nullable >, Derived_class>(); - container_assignment_test< ptr_list< nullable >, - ptr_list, + container_assignment_test< ptr_list< nullable >, + ptr_list, + Derived_class>(); + container_assignment_test< ptr_list, + ptr_list< nullable >, Derived_class>(); - container_assignment_test< ptr_list, - ptr_list< nullable >, - Derived_class>(); test_transfer< ptr_list, ptr_list, Derived_class>(); - + random_access_algorithms_test< ptr_list >(); ptr_list list; list.push_back( new int(0) ); list.push_back( new int(2) ); list.push_back( new int(1) ); list.push_front( new int(3) ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR list.push_front( std::auto_ptr( new int(42) ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + list.push_front( std::unique_ptr( new int(43) ) ); +#endif list.reverse(); } diff --git a/test/ptr_map.cpp b/test/ptr_map.cpp index 68f09a48..ab824c94 100644 --- a/test/ptr_map.cpp +++ b/test/ptr_map.cpp @@ -142,9 +142,18 @@ void ptr_map_test() a_key = get_next_key( a_key ); c.insert( a_key, new T ); a_key = get_next_key( a_key ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c.insert( a_key, std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( a_key, std::unique_ptr( new T ) ); +#endif typename C::auto_type ptr2 = c.release( c.begin() ); +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + std::unique_ptr up = c.release(); +#elif !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR std::auto_ptr ap = c.release(); +#endif c = c2.clone(); BOOST_TEST_MESSAGE( "finished release/clone test" ); @@ -172,7 +181,12 @@ void ptr_map_test() BOOST_CHECK( !c3.empty() ); c3.replace( c3.begin(), new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c3.replace( c3.begin(), std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c3.replace( c3.begin(), std::unique_ptr( new T ) ); +#endif BOOST_TEST_MESSAGE( "finished set/map interface test" ); // @todo: make macro with algorithms so that the right erase() is called. diff --git a/test/ptr_map_adapter.cpp b/test/ptr_map_adapter.cpp index af5d0b70..efbd4eb4 100644 --- a/test/ptr_map_adapter.cpp +++ b/test/ptr_map_adapter.cpp @@ -34,7 +34,12 @@ void test_ptr_map_adapter() ptr_map m; m.insert( joe, new int( 4 ) ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR m.insert( brian, std::auto_ptr( new int( 6 ) ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + m.insert( brian, std::unique_ptr( new int( 6 ) ) ); +#endif m[ joe ] += 56; m[ brian ] += 10; diff --git a/test/ptr_set.cpp b/test/ptr_set.cpp index dcc9ea77..adb79154 100644 --- a/test/ptr_set.cpp +++ b/test/ptr_set.cpp @@ -84,10 +84,21 @@ void test_set() BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); set.insert( new int(0) ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR std::auto_ptr ap( new int(1) ); set.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr up( new int(2) ); + set.insert( std::move( up ) ); +#endif BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr(0) )), bad_ptr_container_operation ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr(nullptr) )), bad_ptr_container_operation ); +#endif test_erase< ptr_set >(); test_erase< ptr_multiset >(); diff --git a/test/ptr_unordered_map.cpp b/test/ptr_unordered_map.cpp index f01818c8..4bde6550 100644 --- a/test/ptr_unordered_map.cpp +++ b/test/ptr_unordered_map.cpp @@ -146,9 +146,18 @@ void ptr_map_test() a_key = get_next_key( a_key ); c.insert( a_key, new T ); a_key = get_next_key( a_key ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c.insert( a_key, std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.insert( a_key, std::unique_ptr( new T ) ); +#endif typename C::auto_type ptr2 = c.release( c.begin() ); +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + std::unique_ptr up = c.release(); +#elif !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR std::auto_ptr ap = c.release(); +#endif c = c2.clone(); BOOST_TEST_MESSAGE( "finished release/clone test" ); @@ -176,7 +185,12 @@ void ptr_map_test() BOOST_CHECK( !c3.empty() ); c3.replace( c3.begin(), new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c3.replace( c3.begin(), std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c3.replace( c3.begin(), std::unique_ptr( new T ) ); +#endif BOOST_TEST_MESSAGE( "finished set/map interface test" ); // @todo: make macro with algorithms so that the right erase() is called. diff --git a/test/ptr_unordered_set.cpp b/test/ptr_unordered_set.cpp index 04769452..b8d57550 100644 --- a/test/ptr_unordered_set.cpp +++ b/test/ptr_unordered_set.cpp @@ -106,10 +106,21 @@ void test_set() BOOST_CHECK_THROW( set.insert( 0 ), bad_ptr_container_operation ); set.insert( new int(0) ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR std::auto_ptr ap( new int(1) ); set.insert( ap ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr up( new int(2) ); + set.insert( std::move( up ) ); +#endif BOOST_CHECK_THROW( (set.replace(set.begin(), 0 )), bad_ptr_container_operation ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR BOOST_CHECK_THROW( (set.replace(set.begin(), std::auto_ptr(0) )), bad_ptr_container_operation ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_CHECK_THROW( (set.replace(set.begin(), std::unique_ptr(nullptr) )), bad_ptr_container_operation ); +#endif test_unordered_interface< ptr_unordered_set, Derived_class >(); test_unordered_interface< ptr_unordered_multiset, Derived_class >(); diff --git a/test/sequence_test_data.hpp b/test/sequence_test_data.hpp index d6f40904..613c3304 100644 --- a/test/sequence_test_data.hpp +++ b/test/sequence_test_data.hpp @@ -25,7 +25,7 @@ void reversible_container_test() using namespace boost; BOOST_TEST_MESSAGE( "starting reversible container test" ); - enum { max_cnt = 10, size = 100 }; + enum { max_cnt = 10 }; C c; set_capacity()( c ); BOOST_CHECK( c.size() == 0 ); @@ -82,7 +82,15 @@ void reversible_container_test() BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size(); hide_warning(s2); c.push_back( new T ); + std::size_t size = 2u; +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR c.push_back( std::auto_ptr( new T ) ); + ++size; +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + c.push_back( std::unique_ptr( new T ) ); + ++size; +#endif bool b = c.empty(); BOOST_CHECK( !c.empty() ); b = is_null( c.begin() ); @@ -98,14 +106,23 @@ void reversible_container_test() BOOST_TEST_MESSAGE( "finished accessors test" ); c.push_back( new T ); - BOOST_CHECK_EQUAL( c.size(), 4u ); + ++size; + BOOST_CHECK_EQUAL( c.size(), size ); c.pop_back(); BOOST_CHECK( !c.empty() ); c.insert( c.end(), new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR std::auto_ptr ap(new T); c.insert( c.end(), ap ); - BOOST_CHECK_EQUAL( c.size(), 5u ); + ++size; +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + std::unique_ptr up( new T ); + c.insert( c.end(), std::move( up ) ); + ++size; +#endif + BOOST_CHECK_EQUAL( c.size(), size ); #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) #else @@ -136,11 +153,20 @@ void reversible_container_test() #else auto_type ptr = c.release( c.begin() ); #endif - std::auto_ptr ap2 = c.release(); +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + std::unique_ptr up2 = c.release(); +#elif !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR + std::auto_ptr ap2 = c.release(); +#endif c = c2.clone(); BOOST_CHECK( !c.empty() ); auto_type ptr2 = c.replace( c.begin(), new T ); +#if !BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR ptr2 = c.replace( c.begin(), std::auto_ptr( new T ) ); +#endif +#ifndef BOOST_NO_CXX11_SMART_PTR + ptr2 = c.replace( c.begin(), std::unique_ptr( new T ) ); +#endif BOOST_TEST_MESSAGE( "finished release/clone/replace test" ); c3.push_back( new T ); diff --git a/test/test_data.hpp b/test/test_data.hpp index 31683602..3b056426 100644 --- a/test/test_data.hpp +++ b/test/test_data.hpp @@ -21,6 +21,14 @@ #include #include +#ifndef BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR +# if defined(BOOST_NO_AUTO_PTR) || BOOST_PTR_CONTAINER_NO_AUTO_PTR +# define BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR 1 +# else +# define BOOST_PTR_CONTAINER_TEST_NO_AUTO_PTR 0 +# endif +#endif + using namespace std; using namespace boost; diff --git a/test/tut1.cpp b/test/tut1.cpp index a66f0801..e9c1e72d 100755 --- a/test/tut1.cpp +++ b/test/tut1.cpp @@ -141,6 +141,12 @@ class farm typedef boost::ptr_deque barn_type; barn_type barn; +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + typedef std::unique_ptr raii_ptr; +#elif !BOOST_PTR_CONTAINER_NO_AUTO_PTR + typedef std::auto_ptr raii_ptr; +#endif + // // An error type // @@ -244,7 +250,7 @@ class farm // // If things are bad, we might choose to sell all animals :-( // - std::auto_ptr sell_farm() + raii_ptr sell_farm() { return barn.release(); } @@ -254,7 +260,7 @@ class farm // else's farm :-) // - void buy_farm( std::auto_ptr other ) + void buy_farm( raii_ptr other ) { // // This line inserts all the animals from 'other' diff --git a/test/view_example.cpp b/test/view_example.cpp index f1007c36..e8ad5dfe 100755 --- a/test/view_example.cpp +++ b/test/view_example.cpp @@ -67,8 +67,12 @@ typedef boost::ptr_vector view_type; // // Our first sort criterium // -struct sort_by_color : std::binary_function +struct sort_by_color { + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + bool operator()( const photon& l, const photon& r ) const { return l.color < r.color; @@ -78,8 +82,12 @@ struct sort_by_color : std::binary_function // // Our second sort criterium // -struct sort_by_direction : std::binary_function +struct sort_by_direction { + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + bool operator()( const photon& l, const photon& r ) const { return l.direction < r.direction; @@ -90,8 +98,12 @@ struct sort_by_direction : std::binary_function // // Our third sort criterium // -struct sort_by_power : std::binary_function +struct sort_by_power { + typedef photon first_argument_type; + typedef photon second_argument_type; + typedef bool result_type; + bool operator()( const photon& l, const photon& r ) const { return l.power < r.power;