forked from boostorg/container
Implemented SCARY iterators for all containers
[SVN r85308]
This commit is contained in:
@@ -61,20 +61,27 @@ namespace container_detail {
|
||||
|
||||
#ifndef BOOST_CONTAINER_VECTOR_ITERATOR_IS_POINTER
|
||||
|
||||
//! Const vector_iterator used to iterate through a vector.
|
||||
template <class Pointer>
|
||||
class vector_const_iterator
|
||||
template <class Pointer, bool IsConst>
|
||||
class vec_iterator
|
||||
{
|
||||
public:
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::template
|
||||
rebind_pointer<const value_type>::type pointer;
|
||||
typedef const value_type& reference;
|
||||
typedef typename if_c
|
||||
< IsConst
|
||||
, typename boost::intrusive::pointer_traits<Pointer>::template
|
||||
rebind_pointer<const value_type>::type
|
||||
, Pointer
|
||||
>::type pointer;
|
||||
typedef typename if_c
|
||||
< IsConst
|
||||
, const value_type&
|
||||
, value_type&
|
||||
>::type reference;
|
||||
|
||||
/// @cond
|
||||
protected:
|
||||
private:
|
||||
Pointer m_ptr;
|
||||
|
||||
public:
|
||||
@@ -84,7 +91,7 @@ class vector_const_iterator
|
||||
Pointer &get_ptr() BOOST_CONTAINER_NOEXCEPT
|
||||
{ return m_ptr; }
|
||||
|
||||
explicit vector_const_iterator(Pointer ptr) BOOST_CONTAINER_NOEXCEPT
|
||||
explicit vec_iterator(Pointer ptr) BOOST_CONTAINER_NOEXCEPT
|
||||
: m_ptr(ptr)
|
||||
{}
|
||||
/// @endcond
|
||||
@@ -92,7 +99,7 @@ class vector_const_iterator
|
||||
public:
|
||||
|
||||
//Constructors
|
||||
vector_const_iterator() BOOST_CONTAINER_NOEXCEPT
|
||||
vec_iterator() BOOST_CONTAINER_NOEXCEPT
|
||||
#ifndef NDEBUG
|
||||
: m_ptr()
|
||||
#else
|
||||
@@ -100,139 +107,80 @@ class vector_const_iterator
|
||||
#endif
|
||||
{}
|
||||
|
||||
vec_iterator(vec_iterator<Pointer, false> const& other) BOOST_CONTAINER_NOEXCEPT
|
||||
: m_ptr(other.get_ptr())
|
||||
{}
|
||||
|
||||
//Pointer like operators
|
||||
reference operator*() const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return *m_ptr; }
|
||||
|
||||
const value_type * operator->() const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return container_detail::to_raw_pointer(m_ptr); }
|
||||
pointer operator->() const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return ::boost::intrusive::pointer_traits<pointer>::pointer_to(this->operator*()); }
|
||||
|
||||
reference operator[](difference_type off) const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return m_ptr[off]; }
|
||||
|
||||
//Increment / Decrement
|
||||
vector_const_iterator& operator++() BOOST_CONTAINER_NOEXCEPT
|
||||
vec_iterator& operator++() BOOST_CONTAINER_NOEXCEPT
|
||||
{ ++m_ptr; return *this; }
|
||||
|
||||
vector_const_iterator operator++(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vector_const_iterator(m_ptr++); }
|
||||
vec_iterator operator++(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vec_iterator(m_ptr++); }
|
||||
|
||||
vector_const_iterator& operator--() BOOST_CONTAINER_NOEXCEPT
|
||||
vec_iterator& operator--() BOOST_CONTAINER_NOEXCEPT
|
||||
{ --m_ptr; return *this; }
|
||||
|
||||
vector_const_iterator operator--(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vector_const_iterator(m_ptr--); }
|
||||
vec_iterator operator--(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vec_iterator(m_ptr--); }
|
||||
|
||||
//Arithmetic
|
||||
vector_const_iterator& operator+=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
vec_iterator& operator+=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ m_ptr += off; return *this; }
|
||||
|
||||
vector_const_iterator& operator-=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
vec_iterator& operator-=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ m_ptr -= off; return *this; }
|
||||
|
||||
friend vector_const_iterator operator+(const vector_const_iterator &x, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vector_const_iterator(x.m_ptr+off); }
|
||||
friend vec_iterator operator+(const vec_iterator &x, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vec_iterator(x.m_ptr+off); }
|
||||
|
||||
friend vector_const_iterator operator+(difference_type off, vector_const_iterator right) BOOST_CONTAINER_NOEXCEPT
|
||||
friend vec_iterator operator+(difference_type off, vec_iterator right) BOOST_CONTAINER_NOEXCEPT
|
||||
{ right.m_ptr += off; return right; }
|
||||
|
||||
friend vector_const_iterator operator-(vector_const_iterator left, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
friend vec_iterator operator-(vec_iterator left, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ left.m_ptr -= off; return left; }
|
||||
|
||||
friend difference_type operator-(const vector_const_iterator &left, const vector_const_iterator& right) BOOST_CONTAINER_NOEXCEPT
|
||||
friend difference_type operator-(const vec_iterator &left, const vec_iterator& right) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return left.m_ptr - right.m_ptr; }
|
||||
|
||||
//Comparison operators
|
||||
friend bool operator== (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator== (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr == r.m_ptr; }
|
||||
|
||||
friend bool operator!= (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator!= (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr != r.m_ptr; }
|
||||
|
||||
friend bool operator< (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator< (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr < r.m_ptr; }
|
||||
|
||||
friend bool operator<= (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator<= (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr <= r.m_ptr; }
|
||||
|
||||
friend bool operator> (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator> (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr > r.m_ptr; }
|
||||
|
||||
friend bool operator>= (const vector_const_iterator& l, const vector_const_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
friend bool operator>= (const vec_iterator& l, const vec_iterator& r) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return l.m_ptr >= r.m_ptr; }
|
||||
};
|
||||
|
||||
//! Iterator used to iterate through a vector
|
||||
template <class Pointer>
|
||||
class vector_iterator
|
||||
: public vector_const_iterator<Pointer>
|
||||
{
|
||||
typedef vector_const_iterator<Pointer> base_t;
|
||||
public:
|
||||
explicit vector_iterator(Pointer ptr) BOOST_CONTAINER_NOEXCEPT
|
||||
: base_t(ptr)
|
||||
{}
|
||||
|
||||
public:
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::element_type value_type;
|
||||
typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
|
||||
typedef Pointer pointer;
|
||||
typedef value_type& reference;
|
||||
|
||||
//Constructors
|
||||
vector_iterator() BOOST_CONTAINER_NOEXCEPT
|
||||
: base_t()
|
||||
{}
|
||||
|
||||
//Pointer like operators
|
||||
reference operator*() const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return *this->m_ptr; }
|
||||
|
||||
value_type* operator->() const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return container_detail::to_raw_pointer(this->m_ptr); }
|
||||
|
||||
reference operator[](difference_type off) const BOOST_CONTAINER_NOEXCEPT
|
||||
{ return this->m_ptr[off]; }
|
||||
|
||||
//Increment / Decrement
|
||||
vector_iterator& operator++() BOOST_CONTAINER_NOEXCEPT
|
||||
{ ++this->m_ptr; return *this; }
|
||||
|
||||
vector_iterator operator++(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vector_iterator(this->m_ptr++); }
|
||||
|
||||
vector_iterator& operator--() BOOST_CONTAINER_NOEXCEPT
|
||||
{ --this->m_ptr; return *this; }
|
||||
|
||||
vector_iterator operator--(int) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return vector_iterator(this->m_ptr--); }
|
||||
|
||||
// Arithmetic
|
||||
vector_iterator& operator+=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ this->m_ptr += off; return *this; }
|
||||
|
||||
vector_iterator& operator-=(difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ this->m_ptr -= off; return *this; }
|
||||
|
||||
friend vector_iterator operator+(vector_iterator left, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ left.m_ptr += off; return left; }
|
||||
|
||||
friend vector_iterator operator+(difference_type off, vector_iterator right) BOOST_CONTAINER_NOEXCEPT
|
||||
{ right.m_ptr += off; return right; }
|
||||
|
||||
friend vector_iterator operator-(vector_iterator left, difference_type off) BOOST_CONTAINER_NOEXCEPT
|
||||
{ left.m_ptr -= off; return left; }
|
||||
};
|
||||
|
||||
} //namespace container_detail {
|
||||
|
||||
template<class Pointer>
|
||||
const Pointer &vector_iterator_get_ptr(const container_detail::vector_const_iterator<Pointer> &it) BOOST_CONTAINER_NOEXCEPT
|
||||
template<class Pointer, bool IsConst>
|
||||
const Pointer &vector_iterator_get_ptr(const container_detail::vec_iterator<Pointer, IsConst> &it) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return it.get_ptr(); }
|
||||
|
||||
template<class Pointer>
|
||||
Pointer &get_ptr(container_detail::vector_const_iterator<Pointer> &it) BOOST_CONTAINER_NOEXCEPT
|
||||
template<class Pointer, bool IsConst>
|
||||
Pointer &get_ptr(container_detail::vec_iterator<Pointer, IsConst> &it) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return it.get_ptr(); }
|
||||
|
||||
namespace container_detail {
|
||||
@@ -251,7 +199,7 @@ struct vector_get_ptr_pointer_to_non_const
|
||||
typedef typename pointer_traits_t
|
||||
::template rebind_pointer<non_const_element_type>::type return_type;
|
||||
|
||||
static return_type get_ptr(const const_pointer &ptr)
|
||||
static return_type get_ptr(const const_pointer &ptr) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return boost::intrusive::pointer_traits<return_type>::const_cast_from(ptr); }
|
||||
};
|
||||
|
||||
@@ -259,7 +207,7 @@ template<class Pointer>
|
||||
struct vector_get_ptr_pointer_to_non_const<Pointer, false>
|
||||
{
|
||||
typedef const Pointer & return_type;
|
||||
static return_type get_ptr(const Pointer &ptr)
|
||||
static return_type get_ptr(const Pointer &ptr) BOOST_CONTAINER_NOEXCEPT
|
||||
{ return ptr; }
|
||||
};
|
||||
|
||||
@@ -565,6 +513,7 @@ struct vector_alloc_holder<Allocator, container_detail::integral_constant<unsign
|
||||
};
|
||||
|
||||
} //namespace container_detail {
|
||||
|
||||
/// @endcond
|
||||
|
||||
//! \class vector
|
||||
@@ -585,11 +534,17 @@ class vector
|
||||
typedef container_detail::integral_constant
|
||||
<unsigned, boost::container::container_detail::version
|
||||
<Allocator>::value > alloc_version;
|
||||
boost::container::container_detail::vector_alloc_holder<Allocator, alloc_version> m_holder;
|
||||
typedef container_detail::vector_alloc_holder<Allocator> base_t;
|
||||
typedef allocator_traits<Allocator> allocator_traits_type;
|
||||
boost::container::container_detail::vector_alloc_holder
|
||||
<Allocator, alloc_version> m_holder;
|
||||
typedef allocator_traits<Allocator> allocator_traits_type;
|
||||
template <class U, class UAllocator>
|
||||
friend class vector;
|
||||
|
||||
typedef typename ::boost::container::allocator_traits
|
||||
<Allocator>::pointer pointer_impl;
|
||||
typedef container_detail::vec_iterator<pointer_impl, false> iterator_impl;
|
||||
typedef container_detail::vec_iterator<pointer_impl, true > const_iterator_impl;
|
||||
|
||||
/// @endcond
|
||||
public:
|
||||
//////////////////////////////////////////////
|
||||
@@ -611,8 +566,8 @@ class vector
|
||||
typedef BOOST_CONTAINER_IMPDEF(pointer) iterator;
|
||||
typedef BOOST_CONTAINER_IMPDEF(const_pointer) const_iterator;
|
||||
#else
|
||||
typedef BOOST_CONTAINER_IMPDEF(container_detail::vector_iterator<pointer>) iterator;
|
||||
typedef BOOST_CONTAINER_IMPDEF(container_detail::vector_const_iterator<pointer>) const_iterator;
|
||||
typedef BOOST_CONTAINER_IMPDEF(iterator_impl) iterator;
|
||||
typedef BOOST_CONTAINER_IMPDEF(const_iterator_impl) const_iterator;
|
||||
#endif
|
||||
typedef BOOST_CONTAINER_IMPDEF(std::reverse_iterator<iterator>) reverse_iterator;
|
||||
typedef BOOST_CONTAINER_IMPDEF(std::reverse_iterator<const_iterator>) const_reverse_iterator;
|
||||
|
||||
Reference in New Issue
Block a user