---
name: "__gnu_debug::_Safe_iterator_base"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/__gnu_debug::_Safe_iterator_base"
---

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

Basic functionality for a safe iterator.

## NAME

\_\_gnu\_debug::\_Safe\_iterator\_base - Basic functionality for a *safe* iterator.

## SYNOPSIS

\#include \<safe\_base.h\>

Inherited by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, map \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, multimap \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, multimap \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, multiset \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, multiset \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence, iterator\_category \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence, std::forward\_iterator\_tag \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_OtherIterator, \_Sequence, std::random\_access\_iterator\_tag \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, set \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, set \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, deque \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, deque \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, forward\_list \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, forward\_list \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, list \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, list \>**, **\_\_gnu\_debug::\_Safe\_iterator\< typename \_Base::\_\_const\_iterator, basic\_string \>**, **\_\_gnu\_debug::\_Safe\_iterator\< typename \_Base::iterator, basic\_string \>**, **\_\_gnu\_debug::\_Safe\_iterator\< typename \_Base::const\_iterator, basic\_string \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, unordered\_map \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, unordered\_map \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, unordered\_multimap \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, unordered\_multimap \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, unordered\_set \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, unordered\_set \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, unordered\_multiset \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, unordered\_multiset \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, vector \>**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_const\_iterator, vector \>**, \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence, std::bidirectional\_iterator\_tag \>, \_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence, std::random\_access\_iterator\_tag \>, **\_\_gnu\_debug::\_Safe\_iterator\< \_Iterator, \_Sequence, \_Category \>**, and **\_\_gnu\_debug::\_Safe\_local\_iterator\_base**.

### Public Member Functions

bool **\_M\_attached\_to** (const \_Safe\_sequence\_base \*\_\_seq) const\
 bool **\_M\_can\_compare** (const **\_Safe\_iterator\_base** &\_\_x) const noexcept\
 void **\_M\_detach\_single** () noexcept\
 void **\_M\_invalidate** ()\
 void **\_M\_reset** () noexcept\
 bool **\_M\_singular** () const noexcept\
 void **\_M\_unlink** () noexcept\

### Public Attributes

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

### Protected Member Functions

constexpr **\_Safe\_iterator\_base** ()\
 constexpr **\_Safe\_iterator\_base** (const \_Safe\_iterator\_base &\_\_x, bool \_\_constant)\
 constexpr **\_Safe\_iterator\_base** (const \_Safe\_sequence\_base \*\_\_seq, bool \_\_constant)\
 void **\_M\_attach** (const \_Safe\_sequence\_base \*\_\_seq, bool \_\_constant)\
 void **\_M\_attach\_single** (const \_Safe\_sequence\_base \*\_\_seq, bool \_\_constant) noexcept\
 void **\_M\_detach** ()\
 \_\_gnu\_cxx::\_\_mutex & **\_M\_get\_mutex** () noexcept\

### Friends

class **\_Safe\_sequence\_base**\

## Detailed Description

Basic functionality for a *safe* iterator.

The \_Safe\_iterator\_base base class implements the functionality of a safe iterator that is not specific to a particular iterator type. It contains a pointer back to the sequence it references along with iterator version information and pointers to form a doubly-linked list of iterators referenced by the container.

This class must not perform any operations that can throw an exception, or the exception guarantees of derived iterators will be broken.

## Constructor & Destructor Documentation

### \_\_gnu\_debug::\_Safe\_iterator\_base::\_Safe\_iterator\_base () \[inline\], \[constexpr\], \[protected\]

Initializes the iterator and makes it singular.

References **\_M\_next**, **\_M\_prior**, **\_M\_sequence**, and **\_M\_version**.

Referenced by **\_Safe\_iterator\_base()**, and **\_M\_can\_compare()**.

### \_\_gnu\_debug::\_Safe\_iterator\_base::\_Safe\_iterator\_base (const \_Safe\_sequence\_base \* \_\_seq, bool \_\_constant) \[inline\], \[constexpr\], \[protected\]

Initialize the iterator to reference the sequence pointed to by \_\_seq. \_\_constant is true when we are initializing a constant iterator, and false if it is a mutable iterator. Note that \_\_seq may be NULL, in which case the iterator will be singular. Otherwise, the iterator will reference \_\_seq and be nonsingular.

References **\_M\_attach()**, **\_M\_next**, **\_M\_prior**, **\_M\_sequence**, and **\_M\_version**.

### \_\_gnu\_debug::\_Safe\_iterator\_base::\_Safe\_iterator\_base (const \_Safe\_iterator\_base & \_\_x, bool \_\_constant) \[inline\], \[constexpr\], \[protected\]

Initializes the iterator to reference the same sequence that \_\_x does. \_\_constant is true if this is a constant iterator, and false if it is mutable.

References **\_Safe\_iterator\_base()**, **\_M\_attach()**, **\_M\_next**, **\_M\_prior**, **\_M\_sequence**, and **\_M\_version**.

## Member Function Documentation

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

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.

References **\_M\_attach()**.

Referenced by **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_M\_attach()**, and **\_M\_attach()**.

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

Likewise, but not thread-safe.

References **\_M\_attach\_single()**.

Referenced by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_M\_attach\_single()**, and **\_M\_attach\_single()**.

### bool \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_attached\_to (const \_Safe\_sequence\_base \* \_\_seq) const \[inline\]

Determines if we are attached to the given sequence.

References **\_M\_attached\_to()**, and **\_M\_sequence**.

Referenced by **\_M\_attached\_to()**.

### bool \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_can\_compare (const \_Safe\_iterator\_base & \_\_x) const \[noexcept\]

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

References **\_Safe\_iterator\_base()**, and **\_M\_can\_compare()**.

Referenced by **\_M\_can\_compare()**.

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

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

References **\_M\_detach()**.

Referenced by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_M\_detach()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, and **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**.

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

Likewise, but not thread-safe.

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

For use in \_Safe\_iterator.

Referenced by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator++()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator++()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**, and **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**.

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_invalidate () \[inline\]

Invalidate the iterator, making it singular.

References **\_M\_invalidate()**, and **\_M\_version**.

Referenced by **\_M\_invalidate()**.

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_reset () \[noexcept\]

Reset all member variables

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

Is this iterator singular?

Referenced by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::\_Safe\_local\_iterator()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::\_Safe\_local\_iterator()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::\_Safe\_local\_iterator()**, **\_\_gnu\_debug::\_\_check\_singular\_aux()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_M\_dereferenceable()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::\_M\_dereferenceable()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_M\_incrementable()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::\_M\_incrementable()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**, and **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**.

### void \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_unlink () \[inline\], \[noexcept\]

Unlink itself

References **\_M\_next**, **\_M\_prior**, and **\_M\_unlink()**.

Referenced by **\_M\_unlink()**.

## Member Data Documentation

### \_Safe\_iterator\_base\* \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_next

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

Referenced by **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_from\_if()**, and **\_M\_unlink()**.

### \_Safe\_iterator\_base\* \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_prior

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

Referenced by **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_from\_if()**, and **\_M\_unlink()**.

### const \_Safe\_sequence\_base\* \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_sequence

The sequence this iterator references; may be NULL to indicate a singular iterator. Stored as pointer-to-const because sequence could be declared as const.

Referenced by **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::\_Safe\_iterator()**, **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_M\_attached\_to()**, **\_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_from\_if()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_iterator\< \_Base\_iterator, map \>::operator=()**, **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**, and **\_\_gnu\_debug::\_Safe\_local\_iterator\< \_OtherIterator, \_UContainer \>::operator=()**.

### unsigned int \_\_gnu\_debug::\_Safe\_iterator\_base::\_M\_version

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.

Referenced by **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_Safe\_iterator\_base()**, **\_M\_invalidate()**, and **\_\_gnu\_debug::\_Safe\_sequence\< \_Sequence \>::\_M\_transfer\_from\_if()**.

## Author

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