Iterator library

Iterator concepts, traits, adaptors, range-access utilities, and the boundary between classic iterators and ranges.

The iterator library is the bridge between algorithms and data structures: it defines how code traverses, reads, writes, advances through, and adapts sequences. This hub is the curated starting point when the question is about iterator capabilities, categories, utilities, or adaptor types rather than a specific container or ranges view.

This page stays focused on iterators and iterator-shaped utilities. It links outward to Ranges, Containers, and Algorithms where the navigation problem becomes broader than iterator mechanics.

# Start Here

Iterator concepts and traversal strength

Start here when you need to know what an iterator is allowed to do: single-pass input, multi-pass forward, bidirectional movement, random access, or contiguous storage guarantees.

Traits and associated types

Use the traits route when generic code needs `value_type`, `difference_type`, tags, or pointer-like adaptation across iterator types.

Iterator adaptors

Start here when you need to wrap an existing iterator to reverse, move, insert, count, or normalize sentinel/iterator pairs.

Navigation helpers

Use these utilities when you already have iterators and need to move them, measure distance, or obtain begin/end/data/size-style access uniformly.

# Quick Map

If you need to...Start withWhy
Describe how far an iterator can move and what guarantees it hasconcepts, iterator tagsThis is the route for capability modeling: readable vs writable, single-pass vs multi-pass, random access vs contiguous layout.
Write generic code against iterator-associated typesiterator_traits, incrementable_traitsTraits provide the canonical metadata and defaults that algorithms and generic adapters rely on.
Reverse or move through an existing iterator interfacereverse_iterator, move_iteratorThese adaptors change traversal or value category behavior without requiring a different underlying container.
Insert through an iterator facade into a containerinsert_iterator, back_insert_iterator, front_insert_iteratorInsertion adaptors are the canonical output-iterator route for algorithms that write into containers.
Advance iterators, compute distances, or get neighboring positionsadvance, distance, next, prevThese helpers abstract over traversal strength while preserving the iterator model.
Access a range through non-member `begin`/`end`/`data`/`size` utilitiesbegin, end, data, size, emptyThese are the classic range-access endpoints that bridge arrays, containers, and some view-like types.
Use iterators backed by streams rather than containersistream_iterator, ostream_iterator, istreambuf_iteratorStream iterators connect iterator-oriented algorithms to formatted or buffer-level I/O.
Navigate the modern ranges-based iterator/sentinel worldranges iterator utilities, Ranges hubRanges reuse iterator ideas but add sentinels, CPOs, and view-oriented navigation beyond the classic iterator page split.

# Iterator Strength Ladder

ConceptMain guaranteeUse it for
input_iteratorReadable, single-pass traversalBasic read pipelines, streaming inputs, and sentinel-based one-pass algorithms.
output_iteratorWritable output progressionAlgorithm sinks and iterator-based output destinations.
forward_iteratorMulti-pass readable traversalStable traversal where revisiting positions is meaningful.
bidirectional_iteratorCan move backward as well as forwardReverse traversal and predecessor-based algorithms.
random_access_iteratorConstant-time jumps and distanceIndex-like traversal, arithmetic on iterators, and random-access algorithms.
contiguous_iteratorElements occupy contiguous memoryAPIs that need raw pointers or contiguous storage guarantees.

# Iterator Families

Traits and tags

Type metadata, iterator categories, difference types, and machinery that generic algorithms inspect.

Traversal adaptors

Adaptors that change how an underlying iterator is traversed or interpreted.

Insertion adaptors

Output-iterator facades that write into containers via insert, push_back, or push_front semantics.

Stream iterators

Iterator-shaped interfaces for stream extraction/insertion and stream-buffer-level traversal.

Range access helpers

Non-member utility functions that discover iteration endpoints, storage pointers, or size/emptiness information.

Ranges iterator utilities

The CPO-based, sentinel-friendly iterator utilities that live on the boundary between classic iterators and the ranges library.

# Utility Operations

OperationUse it forPrimary destinations
Advance / next / prevMoving iterators without manually spelling out repeated increment/decrement logic.advance, next, prev
DistanceMeasuring how far apart two positions are according to iterator strength.distance, ranges::distance
Begin/end/data/size/emptyUniform access to endpoints and shape information for arrays, containers, and some range-like types.begin, end, data, size, empty
Iterator-sentinel normalizationBridging differing iterator/sentinel forms into algorithm-friendly shapes.common_iterator, default_sentinel_t, unreachable_sentinel_t

# Boundary Lines

This hub coversUse a different hub for
Iterator concepts, traits, adaptors, stream iterators, and endpoint/navigation utilities.Ranges for view pipelines and CPO-heavy range navigation, Containers for choosing data structures, and Algorithms for task-oriented operation selection.
Classic iterator-based traversal surfaces.Ranges when the code is primarily range/view/sentinel-first instead of iterator-pair-first.

# Practical Routes

I need to specify iterator requirements

Start from iterator concepts when the job is to constrain templates or understand what a generic algorithm may legally assume.

I need to adapt an existing iterator

Use iterator adaptors when you want a different traversal or insertion behavior without designing a new container interface.

I need common iterator operations

Use the classic utilities first when the problem is traversal math, endpoint discovery, or generic access helpers over existing ranges.