Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Iterator Concepts

Access
Readable Iterator Concept
Writable Iterator Concept
Swappable Iterator Concept
Lvalue Iterator Concept
Traversal
Incrementable Iterator Concept
Single Pass Iterator Concept
Forward Traversal Concept
Bidirectional Traversal Concept
Random Access Traversal Concept

A class or built-in type X models the Readable Iterator concept for value type T if, in addition to X being Assignable and Copy Constructible, the following expressions are valid and respect the stated semantics. U is the type of any specified member of type T.

Table 1.1. Readable Iterator Requirements (in addition to Assignable and Copy Constructible)

Expression

Return Type

Note/Precondition

iterator_traits<X>::value_type

T

Any non-reference, non cv-qualified type

*a

Convertible to T

pre: a is dereferenceable. If a == b then *a is equivalent to *b.

a->m

U&

pre: (*a).m is well-defined. Equivalent to (*a).m.


A class or built-in type X models the Writable Iterator concept if, in addition to X being Copy Constructible, the following expressions are valid and respect the stated semantics. Writable Iterators have an associated set of value types.

Table 1.2. Writable Iterator Requirements (in addition to Copy Constructible)

Expression

Return Type

Precondition

*a = o

pre: The type of o is in the set of value types of X


A class or built-in type X models the Swappable Iterator concept if, in addition to X being Copy Constructible, the following expressions are valid and respect the stated semantics.

Table 1.3. Swappable Iterator Requirements (in addition to Copy Constructible)

Expression

Return Type

Postcondition

iter_swap(a, b)

void

the pointed to values are exchanged


Note: An iterator that is a model of the Readable and Writable Iterator concepts is also a model of Swappable Iterator. --end note

The Lvalue Iterator concept adds the requirement that the return type of operator* type be a reference to the value type of the iterator.

Table 1.4. Lvalue Iterator Requirements

Expression

Return Type

Note/Assertion

*a

T&

T is cv iterator_traits<X>::value_type where cv is an optional cv-qualification. pre: a is dereferenceable. If a == b then *a is equivalent to *b.



PrevUpHomeNext