📄 ptr_sequence_adapter.hpp
字号:
//
// Boost.Pointer Container
//
// Copyright Thorsten Ottosen 2003-2005. 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)
//
// For more information, see http://www.boost.org/libs/ptr_container/
//
#ifndef BOOST_ptr_container_PTR_SEQUENCE_ADAPTER_HPP
#define BOOST_ptr_container_PTR_SEQUENCE_ADAPTER_HPP
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif
#include <boost/ptr_container/detail/reversible_ptr_container.hpp>
#include <boost/ptr_container/indirect_fun.hpp>
#include <boost/ptr_container/detail/void_ptr_iterator.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/iterator/iterator_categories.hpp>
namespace boost
{
namespace ptr_container_detail
{
template
<
class T,
class VoidPtrSeq
>
struct sequence_config
{
typedef BOOST_DEDUCED_TYPENAME remove_nullable<T>::type
U;
typedef VoidPtrSeq
void_container_type;
typedef BOOST_DEDUCED_TYPENAME VoidPtrSeq::allocator_type
allocator_type;
typedef U value_type;
typedef void_ptr_iterator<
BOOST_DEDUCED_TYPENAME VoidPtrSeq::iterator, U >
iterator;
typedef void_ptr_iterator<
BOOST_DEDUCED_TYPENAME VoidPtrSeq::const_iterator, const U >
const_iterator;
#ifdef BOOST_NO_SFINAE
template< class Iter >
static U* get_pointer( Iter i )
{
return static_cast<U*>( *i.base() );
}
#else
template< class Iter >
static U* get_pointer( void_ptr_iterator<Iter,U> i )
{
return static_cast<U*>( *i.base() );
}
template< class Iter >
static U* get_pointer( Iter i )
{
return &*i;
}
#endif
#if defined(BOOST_NO_SFINAE) && !BOOST_WORKAROUND(__MWERKS__, <= 0x3003)
template< class Iter >
static const U* get_const_pointer( Iter i )
{
return static_cast<const U*>( *i.base() );
}
#else // BOOST_NO_SFINAE
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003)
template< class Iter >
static const U* get_const_pointer( void_ptr_iterator<Iter,U> i )
{
return static_cast<const U*>( *i.base() );
}
#else // BOOST_WORKAROUND
template< class Iter >
static const U* get_const_pointer( void_ptr_iterator<Iter,const U> i )
{
return static_cast<const U*>( *i.base() );
}
#endif // BOOST_WORKAROUND
template< class Iter >
static const U* get_const_pointer( Iter i )
{
return &*i;
}
#endif // BOOST_NO_SFINAE
BOOST_STATIC_CONSTANT(bool, allow_null = boost::is_nullable<T>::value );
};
} // ptr_container_detail
template< class Iterator, class T >
inline bool is_null( void_ptr_iterator<Iterator,T> i )
{
return *i.base() == 0;
}
template
<
class T,
class VoidPtrSeq,
class CloneAllocator = heap_clone_allocator
>
class ptr_sequence_adapter : public
ptr_container_detail::reversible_ptr_container< ptr_container_detail::sequence_config<T,VoidPtrSeq>,
CloneAllocator >
{
typedef ptr_container_detail::reversible_ptr_container< ptr_container_detail::sequence_config<T,VoidPtrSeq>,
CloneAllocator >
base_type;
typedef BOOST_DEDUCED_TYPENAME base_type::scoped_deleter scoped_deleter;
typedef ptr_sequence_adapter<T,VoidPtrSeq,CloneAllocator>
this_type;
public:
typedef BOOST_DEDUCED_TYPENAME base_type::value_type value_type;
typedef BOOST_DEDUCED_TYPENAME base_type::reference reference;
typedef BOOST_DEDUCED_TYPENAME base_type::auto_type auto_type;
BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( ptr_sequence_adapter,
base_type )
template< class PtrContainer >
ptr_sequence_adapter( std::auto_ptr<PtrContainer> clone )
: base_type( clone )
{ }
template< class PtrContainer >
void operator=( std::auto_ptr<PtrContainer> clone )
{
base_type::operator=( clone );
}
/////////////////////////////////////////////////////////////
// modifiers
/////////////////////////////////////////////////////////////
void push_back( value_type x ) // strong
{
this->enforce_null_policy( x, "Null pointer in 'push_back()'" );
auto_type ptr( x ); // notrow
this->c_private().push_back( x ); // strong, commit
ptr.release(); // nothrow
}
template< class U >
void push_back( std::auto_ptr<U> x )
{
push_back( x.release() );
}
void push_front( value_type x )
{
this->enforce_null_policy( x, "Null pointer in 'push_front()'" );
auto_type ptr( x ); // nothrow
this->c_private().push_front( x ); // strong, commit
ptr.release(); // nothrow
}
template< class U >
void push_front( std::auto_ptr<U> x )
{
push_front( x.release() );
}
auto_type pop_back()
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"'pop_back()' on empty container" );
auto_type ptr( static_cast<value_type>(
this->c_private().back() ) ); // nothrow
this->c_private().pop_back(); // nothrow
return ptr_container_detail::move( ptr ); // nothrow
}
auto_type pop_front()
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"'pop_front()' on empty container" );
auto_type ptr( static_cast<value_type>(
this->c_private().front() ) ); // nothrow
this->c_private().pop_front(); // nothrow
return ptr_container_detail::move( ptr );
}
reference front()
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"accessing 'front()' on empty container" );
BOOST_ASSERT( !::boost::is_null( this->begin() ) );
return *this->begin();
}
const_reference front() const
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"accessing 'front()' on empty container" );
BOOST_ASSERT( !::boost::is_null( this->begin() ) );
return *this->begin();
}
reference back()
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"accessing 'back()' on empty container" );
BOOST_ASSERT( !::boost::is_null( --this->end() ) );
return *--this->end();
}
const_reference back() const
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
bad_ptr_container_operation,
"accessing 'back()' on empty container" );
BOOST_ASSERT( !::boost::is_null( --this->end() ) );
return *--this->end();
}
public: // deque/vector inerface
reference operator[]( size_type n ) // nothrow
{
BOOST_ASSERT( n < this->size() );
BOOST_ASSERT( !this->is_null( n ) );
return *static_cast<value_type>( this->c_private()[n] );
}
const_reference operator[]( size_type n ) const // nothrow
{
BOOST_ASSERT( n < this->size() );
BOOST_ASSERT( !this->is_null( n ) );
return *static_cast<value_type>( this->c_private()[n] );
}
reference at( size_type n )
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( n >= this->size(), bad_index,
"'at()' out of bounds" );
BOOST_ASSERT( !this->is_null( n ) );
return (*this)[n];
}
const_reference at( size_type n ) const
{
BOOST_PTR_CONTAINER_THROW_EXCEPTION( n >= this->size(), bad_index,
"'at()' out of bounds" );
BOOST_ASSERT( !this->is_null( n ) );
return (*this)[n];
}
public: // vector interface
size_type capacity() const
{
return this->c_private().capacity();
}
void reserve( size_type n )
{
this->c_private().reserve( n );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -