---
name: "__gnu_debug__Safe_iterator"
section: "3"
platform: "linux"
package: "libstdc++6-4.2-doc"
version: "4.2.4-6"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/__gnu_debug__Safe_iterator"
---

# \_\_gnu\_debug\_\_Safe\_iterator(3)

## NAME

\_\_gnu\_debug::\_Safe\_iterator -

## SYNOPSIS

Inherits **\_\_gnu\_debug::\_Safe\_iterator\_base**.

## Detailed Description

### template\<typename \_Iterator, typename \_Sequence\> class \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>

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 68 of file safe\_iterator.h.

### Public Types

typedef \_Iterator **\_Base\_iterator**\
 typedef \_Traits::difference\_type **difference\_type**\
 typedef \_Traits::iterator\_category **iterator\_category**\
 typedef \_Traits::pointer **pointer**\
 typedef \_Traits::reference **reference**\
 typedef \_Traits::value\_type **value\_type**\

### Public Member Functions

void **\_M\_attach** (**\_Safe\_sequence\_base** \*\_\_seq, bool \_\_constant)\
 void **\_M\_attach** (const \_Sequence \*\_\_seq)\
 void **\_M\_attach\_single** (**\_Safe\_sequence\_base** \*\_\_seq, bool \_\_constant)\
 void **\_M\_attach\_single** (const \_Sequence \*\_\_seq)\
 bool **\_M\_attached\_to** (const **\_Safe\_sequence\_base** \*\_\_seq) const \
 bool **\_M\_can\_advance** (const difference\_type &\_\_n) const \
 bool **\_M\_can\_compare** (const **\_Safe\_iterator\_base** &\_\_x) const \
 bool **\_M\_decrementable** () const \
 bool **\_M\_dereferenceable** () const \
 void **\_M\_detach** ()\
 void **\_M\_detach\_single** ()\
 const \_Sequence \* **\_M\_get\_sequence** () const \
 bool **\_M\_incrementable** () const \
 void **\_M\_invalidate** ()\
 void **\_M\_invalidate\_single** ()\
 bool **\_M\_is\_begin** () const \
 bool **\_M\_is\_end** () const \
 bool **\_M\_singular** () const \
 template\<typename \_Other\> bool **\_M\_valid\_range** (const **\_Safe\_iterator**\< \_Other, \_Sequence \> &\_\_rhs) const \
 template\<typename \_MutableIterator\> **\_Safe\_iterator** (const **\_Safe\_iterator**\< \_MutableIterator, typename \_\_gnu\_cxx::\_\_enable\_if\<(std::\_\_are\_same\< \_MutableIterator, typename \_Sequence::iterator::\_Base\_iterator \>::\_\_value), \_Sequence \>::\_\_type \> &\_\_x)\
 **\_Safe\_iterator** (const **\_Safe\_iterator** &\_\_x)\
 **\_Safe\_iterator** (const \_Iterator &\_\_i, const \_Sequence \*\_\_seq)\
 **\_Safe\_iterator** ()\
 \_Iterator **base** () const \
 **operator \_Iterator** () const \
 reference **operator\*** () const \
 **\_Safe\_iterator** **operator+** (const difference\_type &\_\_n) const \
 **\_Safe\_iterator** **operator++** (int)\
 **\_Safe\_iterator** & **operator++** ()\
 **\_Safe\_iterator** & **operator+=** (const difference\_type &\_\_n)\
 **\_Safe\_iterator** **operator-** (const difference\_type &\_\_n) const \
 **\_Safe\_iterator** **operator--** (int)\
 **\_Safe\_iterator** & **operator--** ()\
 **\_Safe\_iterator** & **operator-=** (const difference\_type &\_\_n)\
 pointer **operator-\>** () const \
 **\_Safe\_iterator** & **operator=** (const **\_Safe\_iterator** &\_\_x)\
 reference **operator\[\]** (const difference\_type &\_\_n) const \

### Static Public Member Functions

template\<typename \_Iterator1, typename \_Iterator2\> static **std::pair**\< difference\_type, \_Distance\_precision \> **\_M\_get\_distance** (const \_Iterator1 &\_\_lhs, const \_Iterator2 &\_\_rhs, **std::forward\_iterator\_tag**)\
 template\<typename \_Iterator1, typename \_Iterator2\> static **std::pair**\< difference\_type, \_Distance\_precision \> **\_M\_get\_distance** (const \_Iterator1 &\_\_lhs, const \_Iterator2 &\_\_rhs, **std::random\_access\_iterator\_tag**)\
 template\<typename \_Iterator1, typename \_Iterator2\> static **std::pair**\< difference\_type, \_Distance\_precision \> **\_M\_get\_distance** (const \_Iterator1 &\_\_lhs, const \_Iterator2 &\_\_rhs)\

### Public Attributes

**\_Safe\_iterator\_base** \* **\_M\_next**\
 **\_Safe\_iterator\_base** \* **\_M\_prior**\
 **\_Safe\_sequence\_base** \* **\_M\_sequence**\
 unsigned int **\_M\_version**\

### Protected Member Functions

\_\_gnu\_cxx::\_\_mutex & **\_M\_get\_mutex** ()\

## Constructor & Destructor Documentation

### template\<typename \_Iterator, typename \_Sequence\> \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_Safe\_iterator ()` [inline]`

**Postcondition:**

the iterator is singular and unattached

Definition at line 104 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 113 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular().

### 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 125 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular().

### template\<typename \_Iterator, typename \_Sequence\> template\<typename \_MutableIterator\> \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_Safe\_iterator (const \_Safe\_iterator\< \_MutableIterator, typename \_\_gnu\_cxx::\_\_enable\_if\<(std::\_\_are\_same\< \_MutableIterator, typename \_Sequence::iterator::\_Base\_iterator \>::\_\_value), \_Sequence \>::\_\_type \> & \_\_x)` [inline]`

Converting constructor from a mutable iterator to a constant iterator.

**Precondition:**

`x` is not singular

Definition at line 141 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY.

## Member Function Documentation

### 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.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_attach(), and \_\_gnu\_debug::\_Safe\_iterator\_base::\_Safe\_iterator\_base().

### 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 322 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_attach().

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator=().

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_attach\_single (\_Safe\_sequence\_base \* \_\_seq, bool \_\_constant)` [inherited]`

Likewise, but not thread-safe.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_attach\_single().

### template\<typename \_Iterator, typename \_Sequence\> void \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_attach\_single (const \_Sequence \* \_\_seq)` [inline]`

Likewise, but not thread-safe.

Definition at line 330 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_attach\_single().

### 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 135 of file safe\_base.h.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence.

### 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.

### template\<typename \_Iterator, typename \_Sequence\> bool \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable () const` [inline]`

Is the iterator dereferenceable?

Definition at line 346 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_is\_end(), and \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular().

Referenced by \_\_gnu\_debug::\_\_check\_dereferenceable(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_incrementable(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator\*(), and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator-\>().

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_detach ()` [inherited]`

Detach the iterator for whatever sequence it is attached to, if any.

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_detach\_single ()` [inherited]`

Likewise, but not thread-safe.

### template\<typename \_Iterator, typename \_Sequence\> template\<typename \_Iterator1, typename \_Iterator2\> static std::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 376 of file safe\_iterator.h.

### \_\_gnu\_cxx::\_\_mutex& \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_get\_mutex ()` [protected, inherited]`

For use in **\_Safe\_iterator**.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate().

### template\<typename \_Iterator, typename \_Sequence\> bool \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_incrementable () const` [inline]`

Is the iterator incrementable?

Definition at line 351 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable().

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator++().

### template\<typename \_Iterator, typename \_Sequence\> void \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate ()` [inline]`

Invalidate the iterator, making it singular.

Definition at line 111 of file safe\_iterator.tcc.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_get\_mutex(), and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single().

### template\<typename \_Iterator, typename \_Sequence\> void \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single ()` [inline]`

Likewise, but not thread-safe.

Definition at line 120 of file safe\_iterator.tcc.

References \_\_gnu\_debug::\_Safe\_sequence\_base::\_M\_const\_iterators, \_\_gnu\_debug::\_Safe\_sequence\_base::\_M\_iterators, \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_next, \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence, \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular(), \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_version, and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::base().

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate().

### 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 401 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence.

### 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 405 of file safe\_iterator.h.

References \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable().

### bool \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular () const` [inherited]`

Is this iterator singular?

Referenced by \_\_gnu\_debug::\_\_check\_singular(), \_\_gnu\_debug::\_\_check\_singular\_aux(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_Safe\_iterator(), and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator=().

### template\<typename \_Iterator, typename \_Sequence\> \_Iterator \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::base () const` [inline]`

Return the underlying iterator.

Definition at line 312 of file safe\_iterator.h.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single(), and \_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_iter().

### 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 318 of file safe\_iterator.h.

### template\<typename \_Iterator, typename \_Sequence\> reference \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator\* () const` [inline]`

Iterator dereference.

**Precondition:**

iterator is dereferenceable

Definition at line 175 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable().

### 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 219 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_incrementable().

### template\<typename \_Iterator, typename \_Sequence\> \_Safe\_iterator& \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator++ ()` [inline]`

Iterator preincrement.

**Precondition:**

iterator is incrementable

Definition at line 205 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_incrementable().

### 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 249 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY.

### template\<typename \_Iterator, typename \_Sequence\> \_Safe\_iterator& \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator-- ()` [inline]`

Iterator predecrement.

**Precondition:**

iterator is decrementable

Definition at line 235 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY.

### 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

**Todo**

Use addressof() instead of & operator

Definition at line 191 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_dereferenceable().

### 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 159 of file safe\_iterator.h.

References \_GLIBCXX\_DEBUG\_VERIFY, \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_attach(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_current, \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence, and \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_singular().

## Member Data Documentation

### \_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 78 of file safe\_base.h.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single().

### \_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 74 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 61 of file safe\_base.h.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_attached\_to(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_is\_begin(), \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_is\_end(), \_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_iter(), \_\_gnu\_debug::\_Safe\_iterator\_base::\_Safe\_iterator\_base(), and \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::operator=().

### 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 70 of file safe\_base.h.

Referenced by \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence \>::\_M\_invalidate\_single().

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
