libstdc++
__gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category > Class Template Reference

#include <safe_iterator.h>

Inheritance diagram for __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >:
[legend]

Public Types

typedef _Safe_iterator< _Iterator, _Sequence, iterator_category > _Self
 
typedef _Traits::difference_type difference_type
 
typedef _Traits::iterator_category iterator_category
 
typedef _Iterator iterator_type
 
typedef _Traits::pointer pointer
 
typedef _Traits::reference reference
 
typedef _Traits::value_type value_type
 

Public Member Functions

constexpr _Safe_iterator () noexcept
 
constexpr _Safe_iterator (_Iterator __i, const _Safe_sequence_base *__seq) noexcept
 
constexpr _Safe_iterator (_Safe_iterator &&__x) noexcept
 
constexpr _Safe_iterator (const _Safe_iterator &__x) noexcept
 
template<typename _MutableIterator >
constexpr _Safe_iterator (const _Safe_iterator< _MutableIterator, _Sequence, typename __gnu_cxx::__enable_if< _IsConstant::__value &&std::__are_same< _MutableIterator, _OtherIterator >::__value, _Category >::__type > &__x) noexcept
 
void _M_attach (_Safe_sequence_base *__seq)
 
void _M_attach_single (_Safe_sequence_base *__seq)
 
bool _M_attached_to (const _Safe_sequence_base *__seq) const
 
bool _M_before_dereferenceable () const
 
template<typename _Diff >
bool _M_can_advance (const std::pair< _Diff, _Distance_precision > &__dist, int __way) const
 
bool _M_can_advance (difference_type __n, bool __strict=false) const
 
bool _M_can_compare (const _Safe_iterator_base &__x) const throw ()
 
bool _M_dereferenceable () const
 
void _M_detach_single () throw ()
 
_Distance_traits< _Iterator >::__type _M_get_distance_from_begin () const
 
_Distance_traits< _Iterator >::__type _M_get_distance_to (const _Safe_iterator &__rhs) const
 
_Distance_traits< _Iterator >::__type _M_get_distance_to_end () const
 
__gnu_cxx::__conditional_type< _IsConstant::__value, const_Sequence *, _Sequence * >::__type _M_get_sequence () const
 
bool _M_incrementable () const
 
void _M_invalidate ()
 
bool _M_is_before_begin () const
 
constexpr bool _M_is_begin () const
 
bool _M_is_beginnest () const
 
bool _M_is_end () const
 
void _M_reset () throw ()
 
bool _M_singular () const throw ()
 
void _M_unlink () throw ()
 
bool _M_valid_range (const _Safe_iterator &__rhs, std::pair< difference_type, _Distance_precision > &__dist, bool __check_dereferenceable=true) const
 
bool _M_value_initialized () const
 
constexpr const _Iterator & base () const noexcept
 
constexpr _Iterator & base () noexcept
 
constexpr operator _Iterator () const noexcept
 
constexpr reference operator* () const noexcept
 
constexpr _Safe_iteratoroperator++ () noexcept
 
constexpr _Safe_iterator operator++ (int) noexcept
 
constexpr pointer operator-> () const noexcept
 
constexpr _Safe_iteratoroperator= (_Safe_iterator &&__x) noexcept
 
constexpr _Safe_iteratoroperator= (const _Safe_iterator &__x) noexcept
 

Static Public Member Functions

static constexpr bool _S_constant ()
 

Public Attributes

_Safe_iterator_base_M_next
 
_Safe_iterator_base_M_prior
 
_Safe_sequence_base_M_sequence
 
unsigned int _M_version
 

Protected Types

typedef std::__are_same< typename _Sequence::_Base::const_iterator, _Iterator > _IsConstant
 
typedef __gnu_cxx::__conditional_type< _IsConstant::__value, typename_Sequence::_Base::iterator, typename_Sequence::_Base::const_iterator >::__type _OtherIterator
 

Protected Member Functions

constexpr _Safe_iterator (const _Safe_iterator &__x, _Unchecked) noexcept
 
void _M_attach (_Safe_sequence_base *__seq, bool __constant)
 
void _M_attach_single (_Safe_sequence_base *__seq, bool __constant) throw ()
 
void _M_detach ()
 
__gnu_cxx::__mutex & _M_get_mutex () throw ()
 

Friends

template<typename _IteR >
constexpr friend bool operator== (const _Self &__lhs, const _Safe_iterator< _IteR, _Sequence, iterator_category > &__rhs) noexcept
 
constexpr friend bool operator== (const _Self &__lhs, const _Self &__rhs) noexcept
 

Detailed Description

template<typename _Iterator, typename _Sequence, typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
class __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >

Safe iterator wrapper.

The class template _Safe_iterator is a wrapper around an iterator that tracks the iterator's movement among sequences and checks that operations performed on the "safe" iterator are legal. In additional to the basic iterator operations (which are validated, and then passed to the underlying iterator), _Safe_iterator has member functions for iterator invalidation, attaching/detaching the iterator from sequences, and querying the iterator's state.

Note that _Iterator must be the first base class so that it gets initialized before the iterator is being attached to the container's list of iterators and it is being detached before _Iterator get destroyed. Otherwise it would result in a data race.

Definition at line 130 of file safe_iterator.h.

Member Typedef Documentation

◆ _IsConstant

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef std::__are_same<typename _Sequence::_Base::const_iterator, _Iterator> __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_IsConstant
protected

Definition at line 141 of file safe_iterator.h.

◆ _OtherIterator

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef __gnu_cxx::__conditional_type<_IsConstant::__value,typename_Sequence::_Base::iterator,typename_Sequence::_Base::const_iterator>::__type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_OtherIterator
protected

Definition at line 146 of file safe_iterator.h.

◆ _Self

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Safe_iterator<_Iterator, _Sequence, iterator_category> __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Self

Definition at line 542 of file safe_iterator.h.

◆ difference_type

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Traits::difference_type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::difference_type

Definition at line 162 of file safe_iterator.h.

◆ iterator_category

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Traits::iterator_category __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::iterator_category

Definition at line 160 of file safe_iterator.h.

◆ iterator_type

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Iterator __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::iterator_type

Definition at line 159 of file safe_iterator.h.

◆ pointer

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Traits::pointer __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::pointer

Definition at line 164 of file safe_iterator.h.

◆ reference

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Traits::reference __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::reference

Definition at line 163 of file safe_iterator.h.

◆ value_type

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
typedef _Traits::value_type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::value_type

Definition at line 161 of file safe_iterator.h.

Constructor & Destructor Documentation

◆ _Safe_iterator() [1/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( const _Safe_iterator< _Iterator, _Sequence, _Category > &  __x,
_Unchecked   
)
inlineconstexprprotectednoexcept

Definition at line 151 of file safe_iterator.h.

◆ _Safe_iterator() [2/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( )
inlineconstexprnoexcept
Postcondition
the iterator is singular and unattached

Definition at line 172 of file safe_iterator.h.

◆ _Safe_iterator() [3/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( _Iterator  __i,
const _Safe_sequence_base __seq 
)
inlineconstexprnoexcept

Safe iterator construction from an unsafe iterator and its sequence.

Precondition
seq is not NULL
Postcondition
this is not singular

Definition at line 182 of file safe_iterator.h.

◆ _Safe_iterator() [4/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( const _Safe_iterator< _Iterator, _Sequence, _Category > &  __x)
inlineconstexprnoexcept

◆ _Safe_iterator() [5/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( _Safe_iterator< _Iterator, _Sequence, _Category > &&  __x)
inlineconstexprnoexcept

◆ _Safe_iterator() [6/6]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
template<typename _MutableIterator >
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_Safe_iterator ( const _Safe_iterator< _MutableIterator, _Sequence, typename __gnu_cxx::__enable_if< _IsConstant::__value &&std::__are_same< _MutableIterator, _OtherIterator >::__value, _Category >::__type > &  __x)
inlineconstexprnoexcept

Member Function Documentation

◆ _M_attach() [1/2]

◆ _M_attach() [2/2]

void __gnu_debug::_Safe_iterator_base::_M_attach ( _Safe_sequence_base __seq,
bool  __constant 
)
protectedinherited

Attaches this iterator to the given sequence, detaching it from whatever sequence it was attached to originally. If the new sequence is the NULL pointer, the iterator is left unattached.

Referenced by __gnu_debug::_Safe_iterator_base::_Safe_iterator_base(), __gnu_debug::_Safe_iterator_base::_Safe_iterator_base(), and __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_attach().

◆ _M_attach_single() [1/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
void __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_attach_single ( _Safe_sequence_base __seq)
inline

◆ _M_attach_single() [2/2]

void __gnu_debug::_Safe_iterator_base::_M_attach_single ( _Safe_sequence_base __seq,
bool  __constant 
)
throw (
)
protectedinherited

◆ _M_attached_to()

bool __gnu_debug::_Safe_iterator_base::_M_attached_to ( const _Safe_sequence_base __seq) const
inlineinherited

Determines if we are attached to the given sequence.

Definition at line 145 of file safe_base.h.

References __gnu_debug::_Safe_iterator_base::_M_sequence.

◆ _M_before_dereferenceable()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_before_dereferenceable ( ) const
inline

◆ _M_can_advance() [1/2]

template<typename _Iterator , typename _Sequence , typename _Category >
template<typename _Diff >
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_can_advance ( const std::pair< _Diff, _Distance_precision > &  __dist,
int  __way 
) const

Definition at line 113 of file safe_iterator.tcc.

◆ _M_can_advance() [2/2]

template<typename _Iterator , typename _Sequence , typename _Category >
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_can_advance ( difference_type  __n,
bool  __strict = false 
) const

Definition at line 86 of file safe_iterator.tcc.

◆ _M_can_compare()

bool __gnu_debug::_Safe_iterator_base::_M_can_compare ( const _Safe_iterator_base __x) const
throw (
)
inherited

Can we compare this iterator to the given iterator __x? Returns true if both iterators are nonsingular and reference the same sequence.

◆ _M_dereferenceable()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_dereferenceable ( ) const
inline

◆ _M_detach()

void __gnu_debug::_Safe_iterator_base::_M_detach ( )
protectedinherited

◆ _M_detach_single()

void __gnu_debug::_Safe_iterator_base::_M_detach_single ( )
throw (
)
inherited

Likewise, but not thread-safe.

Referenced by __gnu_debug::_Safe_sequence< _Sequence >::_M_transfer_from_if().

◆ _M_get_distance_from_begin()

template<typename _Iterator , typename _Sequence , typename _Category >
_Distance_traits< _Iterator >::__type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_get_distance_from_begin

Definition at line 38 of file safe_iterator.tcc.

◆ _M_get_distance_to()

template<typename _Iterator , typename _Sequence , typename _Category >
_Distance_traits< _Iterator >::__type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_get_distance_to ( const _Safe_iterator< _Iterator, _Sequence, _Category > &  __rhs) const

Definition at line 126 of file safe_iterator.tcc.

◆ _M_get_distance_to_end()

template<typename _Iterator , typename _Sequence , typename _Category >
_Distance_traits< _Iterator >::__type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_get_distance_to_end

Definition at line 62 of file safe_iterator.tcc.

◆ _M_get_mutex()

◆ _M_get_sequence()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
__gnu_cxx::__conditional_type< _IsConstant::__value, const_Sequence *, _Sequence * >::__type __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_get_sequence ( ) const
inline

Definition at line 502 of file safe_iterator.h.

◆ _M_incrementable()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_incrementable ( ) const
inline

◆ _M_invalidate()

void __gnu_debug::_Safe_iterator_base::_M_invalidate ( )
inlineinherited

Invalidate the iterator, making it singular.

Definition at line 160 of file safe_base.h.

References __gnu_debug::_Safe_iterator_base::_M_version.

◆ _M_is_before_begin()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_is_before_begin ( ) const
inline

Is this iterator equal to the sequence's before_begin() iterator if any?

Definition at line 531 of file safe_iterator.h.

Referenced by __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_dereferenceable().

◆ _M_is_begin()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_is_begin ( ) const
inlineconstexpr

Is this iterator equal to the sequence's begin() iterator?

Definition at line 520 of file safe_iterator.h.

References __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::base().

◆ _M_is_beginnest()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_is_beginnest ( ) const
inline

Is this iterator equal to the sequence's before_begin() iterator if any or begin() otherwise?

Definition at line 537 of file safe_iterator.h.

◆ _M_is_end()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_is_end ( ) const
inline

◆ _M_reset()

void __gnu_debug::_Safe_iterator_base::_M_reset ( )
throw (
)
inherited

Reset all member variables

◆ _M_singular()

◆ _M_unlink()

void __gnu_debug::_Safe_iterator_base::_M_unlink ( )
throw (
)
inlineinherited

◆ _M_valid_range()

template<typename _Iterator , typename _Sequence , typename _Category >
bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_valid_range ( const _Safe_iterator< _Iterator, _Sequence, _Category > &  __rhs,
std::pair< difference_type, _Distance_precision > &  __dist,
bool  __check_dereferenceable = true 
) const

Definition at line 195 of file safe_iterator.tcc.

◆ _M_value_initialized()

◆ _S_constant()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
static constexpr bool __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_S_constant ( )
inlinestaticconstexpr

◆ base() [1/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr const _Iterator & __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::base ( ) const
inlineconstexprnoexcept

Definition at line 437 of file safe_iterator.h.

◆ base() [2/2]

◆ operator _Iterator()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::operator _Iterator ( ) const
inlineconstexprnoexcept

Conversion to underlying non-debug iterator to allow better interaction with non-debug containers.

Definition at line 444 of file safe_iterator.h.

◆ operator*()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr reference __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::operator* ( ) const
inlineconstexprnoexcept

◆ operator++() [1/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr _Safe_iterator & __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::operator++ ( )
inlineconstexprnoexcept

◆ operator++() [2/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr _Safe_iterator __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::operator++ ( int  )
inlineconstexprnoexcept

Iterator postincrement.

Precondition
iterator is incrementable

Definition at line 408 of file safe_iterator.h.

References __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::_M_incrementable().

◆ operator->()

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr pointer __gnu_debug::_Safe_iterator< _Iterator, _Sequence, _Category >::operator-> ( ) const
inlineconstexprnoexcept

◆ operator=() [1/2]

◆ operator=() [2/2]

Friends And Related Symbol Documentation

◆ operator== [1/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
template<typename _IteR >
constexpr friend bool operator== ( const _Self __lhs,
const _Safe_iterator< _IteR, _Sequence, iterator_category > &  __rhs 
)
friend

Definition at line 557 of file safe_iterator.h.

◆ operator== [2/2]

template<typename _Iterator , typename _Sequence , typename _Category = typename std::iterator_traits<_Iterator>::iterator_category>
constexpr friend bool operator== ( const _Self __lhs,
const _Self __rhs 
)
friend

Definition at line 547 of file safe_iterator.h.

Member Data Documentation

◆ _M_next

_Safe_iterator_base* __gnu_debug::_Safe_iterator_base::_M_next
inherited

Pointer to the next iterator in the sequence's list of iterators. Only valid when _M_sequence != NULL.

Definition at line 74 of file safe_base.h.

Referenced by __gnu_debug::_Safe_sequence< _SafeSequence >::_M_invalidate_if(), __gnu_debug::_Safe_sequence< _Sequence >::_M_transfer_from_if(), and __gnu_debug::_Safe_iterator_base::_M_unlink().

◆ _M_prior

_Safe_iterator_base* __gnu_debug::_Safe_iterator_base::_M_prior
inherited

Pointer to the previous iterator in the sequence's list of iterators. Only valid when _M_sequence != NULL.

Definition at line 70 of file safe_base.h.

Referenced by __gnu_debug::_Safe_sequence< _SafeSequence >::_M_invalidate_if(), __gnu_debug::_Safe_sequence< _Sequence >::_M_transfer_from_if(), and __gnu_debug::_Safe_iterator_base::_M_unlink().

◆ _M_sequence

◆ _M_version

unsigned int __gnu_debug::_Safe_iterator_base::_M_version
inherited

The documentation for this class was generated from the following files: