# __gnu_debug::Safe_iterator< Iterator, Sequence > Class Template Reference

Safe iterator wrapper. More...

`#include <safe_iterator.h>`

Inheritance diagram for __gnu_debug::Safe_iterator< Iterator, Sequence >:

[legend]
Collaboration diagram for __gnu_debug::Safe_iterator< Iterator, Sequence >:

[legend]
List of all members.

## Public Member Functions

| Safe_iterator ()
| the iterator is singular and unattached
| Safe_iterator (const Iterator &__i, const Sequence *seq)
| Safe iterator construction from an unsafe iterator and its sequence.
| Safe_iterator (const Safe_iterator &x)
| Copy construction.
template<typename MutableIterator> | Safe_iterator (const Safe_iterator< MutableIterator, typename std::__enable_if< Sequence,(std::are_same< MutableIterator, typename Sequence::iterator::Base_iterator >::M_type) >::M_type > &x)
| Converting constructor from a mutable iterator to a constant iterator.
Safe_iterator & | operator= (const Safe_iterator &x)
| Copy assignment.
reference | operator * () const
| Iterator dereference.
pointer | operator-> () const
| Iterator dereference.
Safe_iterator & | operator++ ()
| Iterator preincrement.
Safe_iterator | operator++ (int)
| Iterator postincrement.
Safe_iterator & | operator-- ()
| Iterator predecrement.
Safe_iterator | operator-- (int)
| Iterator postdecrement.
Iterator | base () const
| Return the underlying iterator.
| operator Iterator () const
| Conversion to underlying non-debug iterator to allow better interaction with non-debug containers.
void | M_attach (const Sequence *seq)
void | M_invalidate ()
bool | M_dereferenceable () const
| Is the iterator dereferenceable?
bool | M_incrementable () const
| Is the iterator incrementable?
bool | M_is_begin () const
| Is this iterator equal to the sequence's begin() iterator?
bool | M_is_end () const
| Is this iterator equal to the sequence's end() iterator?
void | M_attach (Safe_sequence_base *seq, bool constant)
void | M_detach ()
bool | M_attached_to (const Safe_sequence_base *seq) const
bool | M_singular () const
bool | M_can_compare (const Safe_iterator_base &x) const

## Static Public Member Functions

template<typename Iterator1, typename Iterator2> pair< difference_type, Distance_precision > | M_get_distance (const Iterator1 &__lhs, const Iterator2 &__rhs)

## Public Attributes

Safe_sequence_base * | M_sequence
unsigned int | M_version
Safe_iterator_base * | M_prior
Safe_iterator_base * | M_next

## Private Types

enum | Distance_precision

## Private Member Functions

bool | M_constant () const
| Determine if this is a constant iterator.

## Private Attributes

Iterator | M_current
| The underlying iterator.

## Detailed Description

### template<typename Iterator, typename Sequence>
class __gnu_debug::Safe_iterator< Iterator, Sequence >

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.

Definition at line 64 of file safe_iterator.h.

## Member Enumeration Documentation

template<typename Iterator, typename Sequence>
enum __gnu_debug::Safe_iterator::Distance_precision`[private]`

| The precision to which we can calculate the distance between two iterators. Definition at line 71 of file safe_iterator.h.

## Constructor & Destructor Documentation

template<typename Iterator, typename Sequence>
__gnu_debug::Safe_iterator< Iterator, Sequence >::Safe_iterator | ( |  | ) | `[inline]`

| the iterator is singular and unattached Definition at line 100 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
__gnu_debug::Safe_iterator< Iterator, Sequence >::Safe_iterator | ( | const Iterator & | __i,
|  | const Sequence * | seq
| ) | `[inline]`

Safe iterator construction from an unsafe iterator and its sequence.

Precondition:
  `seq` is not NULL

Postcondition:
  this is not singular

Definition at line 109 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
__gnu_debug::Safe_iterator< Iterator, Sequence >::Safe_iterator | ( | const Safe_iterator< Iterator, Sequence > & | x | ) | `[inline]`

Copy construction.

Precondition:
  `x` is not singular

Definition at line 121 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
template<typename MutableIterator>
__gnu_debug::Safe_iterator< Iterator, Sequence >::Safe_iterator | ( | const Safe_iterator< MutableIterator, typename std::__enable_if< Sequence,(std::are_same< MutableIterator, typename Sequence::iterator::Base_iterator >::M_type) >::M_type > & | x | ) | `[inline]`

Converting constructor from a mutable iterator to a constant iterator.

Precondition:
  `x` is not singular

Definition at line 137 of file safe_iterator.h.

## Member Function Documentation

template<typename Iterator, typename Sequence>
Iterator __gnu_debug::Safe_iterator< Iterator, Sequence >::base | ( |  | ) | const`[inline]`

| Return the underlying iterator. Definition at line 310 of file safe_iterator.h. Referenced by __gnu_debug::Safe_iterator< Iterator, Sequence >::M_invalidate().

void __gnu_debug::Safe_iterator_base::M_attach | ( | Safe_sequence_base * | seq,
|  | bool | constant
| ) | `[inherited]`

| 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. Definition at line 184 of file debug.cc.

template<typename Iterator, typename Sequence>
void __gnu_debug::Safe_iterator< Iterator, Sequence >::M_attach | ( | const Sequence * | seq | ) | `[inline]`

| Attach iterator to the given sequence. Definition at line 320 of file safe_iterator.h.

bool __gnu_debug::Safe_iterator_base::M_attached_to | ( | const Safe_sequence_base * | seq | ) | const`[inline, inherited]`

| Determines if we are attached to the given sequence. Definition at line 120 of file safe_base.h.

bool __gnu_debug::Safe_iterator_base::M_can_compare | ( | const Safe_iterator_base & | x | ) | const`[inherited]`

| Can we compare this iterator to the given iterator `x`? Returns true if both iterators are nonsingular and reference the same sequence. Definition at line 242 of file debug.cc.

template<typename Iterator, typename Sequence>
bool __gnu_debug::Safe_iterator< Iterator, Sequence >::M_constant | ( |  | ) | const`[inline, private]`

| Determine if this is a constant iterator. Definition at line 83 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
bool __gnu_debug::Safe_iterator< Iterator, Sequence >::M_dereferenceable | ( |  | ) | const`[inline]`

| Is the iterator dereferenceable? Definition at line 332 of file safe_iterator.h.

void __gnu_debug::Safe_iterator_base::M_detach | ( |  | ) | `[inherited]`

| Detach the iterator for whatever sequence it is attached to, if any. Definition at line 213 of file debug.cc.

template<typename Iterator, typename Sequence>
template<typename Iterator1, typename Iterator2>
pair<difference_type, Distance_precision> __gnu_debug::Safe_iterator< Iterator, Sequence >::M_get_distance | ( | const Iterator1 & | __lhs,
|  | const Iterator2 & | __rhs
| ) | `[inline, static]`

| Determine the distance between two iterators with some known precision. Definition at line 362 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
bool __gnu_debug::Safe_iterator< Iterator, Sequence >::M_incrementable | ( |  | ) | const`[inline]`

| Is the iterator incrementable? Definition at line 337 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
void __gnu_debug::Safe_iterator< Iterator, Sequence >::M_invalidate | ( |  | ) |

| Invalidate the iterator, making it singular. Definition at line 112 of file safe_iterator.tcc. References __gnu_debug::Safe_iterator< Iterator, Sequence >::base().

template<typename Iterator, typename Sequence>
bool __gnu_debug::Safe_iterator< Iterator, Sequence >::M_is_begin | ( |  | ) | const`[inline]`

| Is this iterator equal to the sequence's begin() iterator? Definition at line 387 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
bool __gnu_debug::Safe_iterator< Iterator, Sequence >::M_is_end | ( |  | ) | const`[inline]`

| Is this iterator equal to the sequence's end() iterator? Definition at line 391 of file safe_iterator.h.

bool __gnu_debug::Safe_iterator_base::M_singular | ( |  | ) | const`[inherited]`

| Is this iterator singular? Definition at line 237 of file debug.cc.

template<typename Iterator, typename Sequence>
reference __gnu_debug::Safe_iterator< Iterator, Sequence >::operator * | ( |  | ) | const`[inline]`

Iterator dereference.

Precondition:
  iterator is dereferenceable

Definition at line 173 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
__gnu_debug::Safe_iterator< Iterator, Sequence >::operator Iterator | ( |  | ) | const`[inline]`

| Conversion to underlying non-debug iterator to allow better interaction with non-debug containers. Definition at line 316 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
Safe_iterator __gnu_debug::Safe_iterator< Iterator, Sequence >::operator++ | ( | int |  | ) | `[inline]`

Iterator postincrement.

Precondition:
  iterator is incrementable

Definition at line 217 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
Safe_iterator& __gnu_debug::Safe_iterator< Iterator, Sequence >::operator++ | ( |  | ) | `[inline]`

Iterator preincrement.

Precondition:
  iterator is incrementable

Definition at line 203 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
Safe_iterator __gnu_debug::Safe_iterator< Iterator, Sequence >::operator-- | ( | int |  | ) | `[inline]`

Iterator postdecrement.

Precondition:
  iterator is decrementable

Definition at line 247 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
Safe_iterator& __gnu_debug::Safe_iterator< Iterator, Sequence >::operator-- | ( |  | ) | `[inline]`

Iterator predecrement.

Precondition:
  iterator is decrementable

Definition at line 233 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
pointer __gnu_debug::Safe_iterator< Iterator, Sequence >::operator-> | ( |  | ) | const`[inline]`

Iterator dereference.

Precondition:
  iterator is dereferenceable

Todo:
  Make this correct w.r.t. iterators that return proxies

  Use addressof() instead of & operator

Definition at line 189 of file safe_iterator.h.

template<typename Iterator, typename Sequence>
Safe_iterator& __gnu_debug::Safe_iterator< Iterator, Sequence >::operator= | ( | const Safe_iterator< Iterator, Sequence > & | x | ) | `[inline]`

Copy assignment.

Precondition:
  `x` is not singular

Definition at line 157 of file safe_iterator.h.

## Member Data Documentation

template<typename Iterator, typename Sequence>
Iterator __gnu_debug::Safe_iterator< Iterator, Sequence >::M_current`[private]`

| The underlying iterator. Definition at line 79 of file safe_iterator.h.

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 72 of file safe_base.h.

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 68 of file safe_base.h.

Safe_sequence_base* __gnu_debug::Safe_iterator_base::M_sequence`[inherited]`

| The sequence this iterator references; may be NULL to indicate a singular iterator. Definition at line 55 of file safe_base.h.

unsigned int __gnu_debug::Safe_iterator_base::M_version`[inherited]`

| The version number of this iterator. The sentinel value 0 is used to indicate an invalidated iterator (i.e., one that is singular because of an operation on the container). This version number must equal the version number in the sequence referenced by M_sequence for the iterator to be non-singular. Definition at line 64 of file safe_base.h.

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

- safe_iterator.h
- safe_iterator.tcc