Skip to content

Commit

Permalink
Conditionally provide interfaces based on deprecated/removed std::aut…
Browse files Browse the repository at this point in the history
…o_ptr and/or std::unique_ptr, and replace C++98 function adapters by inline typedefs.

Signed-off-by: Daniela Engert <dani@ngrt.de>
  • Loading branch information
DanielaE committed Nov 20, 2017
1 parent e67da89 commit b805b3c
Show file tree
Hide file tree
Showing 20 changed files with 603 additions and 24 deletions.
18 changes: 18 additions & 0 deletions include/boost/ptr_container/detail/associative_ptr_container.hpp
Expand Up @@ -103,10 +103,18 @@ namespace ptr_container_detail
: base_type( first, last, hash, pred, a )
{ }

#ifndef BOOST_NO_AUTO_PTR
template< class PtrContainer >
explicit associative_ptr_container( std::auto_ptr<PtrContainer> r )
: base_type( r )
{ }
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< class PtrContainer >
explicit associative_ptr_container( std::unique_ptr<PtrContainer> r )
: base_type( std::move( r ) )
{ }
#endif

associative_ptr_container( const associative_ptr_container& r )
: base_type( r.begin(), r.end(), container_type() )
Expand All @@ -117,12 +125,22 @@ namespace ptr_container_detail
: base_type( r.begin(), r.end(), container_type() )
{ }

#ifndef BOOST_NO_AUTO_PTR
template< class PtrContainer >
associative_ptr_container& operator=( std::auto_ptr<PtrContainer> 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<PtrContainer> r ) // nothrow
{
base_type::operator=( std::move( r ) );
return *this;
}
#endif

associative_ptr_container& operator=( associative_ptr_container r ) // strong
{
Expand Down
105 changes: 96 additions & 9 deletions include/boost/ptr_container/detail/reversible_ptr_container.hpp
Expand Up @@ -345,12 +345,21 @@ namespace ptr_container_detail
explicit reversible_ptr_container( const allocator_type& a )
: c_( a )
{ }


#ifndef BOOST_NO_AUTO_PTR
template< class PtrContainer >
explicit reversible_ptr_container( std::auto_ptr<PtrContainer> clone )
{
swap( *clone );
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< class PtrContainer >
explicit reversible_ptr_container( std::unique_ptr<PtrContainer> clone )
{
swap( *clone );
}
#endif

reversible_ptr_container( const reversible_ptr_container& r )
{
Expand All @@ -363,12 +372,22 @@ namespace ptr_container_detail
constructor_impl( r.begin(), r.end(), std::forward_iterator_tag() );
}

#ifndef BOOST_NO_AUTO_PTR
template< class PtrContainer >
reversible_ptr_container& operator=( std::auto_ptr<PtrContainer> clone ) // nothrow
{
swap( *clone );
return *this;
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< class PtrContainer >
reversible_ptr_container& operator=( std::unique_ptr<PtrContainer> clone ) // nothrow
{
swap( *clone );
return *this;
}
#endif

reversible_ptr_container& operator=( reversible_ptr_container r ) // strong
{
Expand Down Expand Up @@ -588,11 +607,20 @@ namespace ptr_container_detail
return res;
}

#ifndef BOOST_NO_AUTO_PTR
template< class U >
iterator insert( iterator before, std::auto_ptr<U> x )
{
return insert( before, x.release() );
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< class U >
iterator insert( iterator before, std::unique_ptr<U> x )
{
return insert( before, x.release() );
}
#endif

iterator erase( iterator x ) // nothrow
{
Expand Down Expand Up @@ -650,11 +678,20 @@ namespace ptr_container_detail
return boost::ptr_container_detail::move( old );
}

#ifndef BOOST_NO_AUTO_PTR
template< class U >
auto_type replace( iterator where, std::auto_ptr<U> x )
{
return replace( where, x.release() );
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< class U >
auto_type replace( iterator where, std::unique_ptr<U> x )
{
return replace( where, x.release() );
}
#endif

auto_type replace( size_type idx, Ty_* x ) // strong
{
Expand All @@ -669,11 +706,20 @@ namespace ptr_container_detail
return boost::ptr_container_detail::move( old );
}

#ifndef BOOST_NO_AUTO_PTR
template< class U >
auto_type replace( size_type idx, std::auto_ptr<U> 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<U> x )
{
return replace( idx, x.release() );
}
#endif

}; // 'reversible_ptr_container'

Expand All @@ -689,33 +735,74 @@ 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 ) \

#ifndef BOOST_NO_AUTO_PTR
#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) \
explicit PC( std::auto_ptr<this_type> r ) \
: base_type ( r ) { } \
\
PC& operator=( std::auto_ptr<this_type> r ) \
{ \
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<this_type> r ) \
: base_type ( std::move( r ) ) { } \
\
PC& operator=( std::unique_ptr<this_type> r ) \
{ \
base_type::operator=( std::move( r ) ); \
return *this; \
}
#else
#define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type )
#endif

#ifndef BOOST_NO_AUTO_PTR
#define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \
std::auto_ptr<this_type> release() \
{ \
std::auto_ptr<this_type> ptr( new this_type );\
this->swap( *ptr ); \
return ptr; \
} \
BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
\
std::auto_ptr<this_type> clone() const \
{ \
return std::auto_ptr<this_type>( 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<this_type> release() \
{ \
std::unique_ptr<this_type> ptr( new this_type );\
this->swap( *ptr ); \
return ptr; \
} \
\
std::unique_ptr<this_type> clone() const \
{ \
return std::unique_ptr<this_type>( 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 ) \
\
Expand Down
58 changes: 56 additions & 2 deletions include/boost/ptr_container/ptr_array.hpp
Expand Up @@ -102,21 +102,37 @@ namespace boost
static_cast<const T*>( &r[i] ) );
}

#ifndef BOOST_NO_AUTO_PTR
explicit ptr_array( std::auto_ptr<this_type> r )
: base_class( r ) { }
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
explicit ptr_array( std::unique_ptr<this_type> r )
: base_class( std::move( r ) ) { }
#endif

ptr_array& operator=( ptr_array r )
{
this->swap( r );
return *this;
}

#ifndef BOOST_NO_AUTO_PTR
ptr_array& operator=( std::auto_ptr<this_type> r )
{
base_class::operator=(r);
return *this;
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
ptr_array& operator=( std::unique_ptr<this_type> r )
{
base_class::operator=(std::move(r));
return *this;
}
#endif

#ifndef BOOST_NO_AUTO_PTR
std::auto_ptr<this_type> release()
{
std::auto_ptr<this_type> ptr( new this_type );
Expand All @@ -127,12 +143,32 @@ namespace boost
std::auto_ptr<this_type> clone() const
{
std::auto_ptr<this_type> pa( new this_type );
clone_array_elements( *pa );
return pa;
}
#else
std::unique_ptr<this_type> release()
{
std::unique_ptr<this_type> ptr( new this_type );
this->swap( *ptr );
return ptr;
}

std::unique_ptr<this_type> clone() const
{
std::unique_ptr<this_type> 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
Expand All @@ -158,11 +194,20 @@ namespace boost
return boost::ptr_container::move(res); // nothrow
}

#ifndef BOOST_NO_AUTO_PTR
template< size_t idx, class V >
auto_type replace( std::auto_ptr<V> r )
{
return replace<idx>( r.release() );
}
#endif
#ifndef BOOST_NO_CXX11_SMART_PTR
template< size_t idx, class V >
auto_type replace( std::unique_ptr<V> r )
{
return replace<idx>( r.release() );
}
#endif

auto_type replace( size_t idx, U* r ) // strong
{
Expand All @@ -177,11 +222,20 @@ namespace boost
return boost::ptr_container::move(res); // nothrow
}

#ifndef BOOST_NO_AUTO_PTR
template< class V >
auto_type replace( size_t idx, std::auto_ptr<V> 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<V> r )
{
return replace( idx, r.release() );
}
#endif

using base_class::at;

Expand Down

0 comments on commit b805b3c

Please sign in to comment.