C++ › Ranges & Views

What are the range concepts (input_range, forward_range, etc.)?

Advanced

Answer

Ranges are categorized by iterator capability via concepts: input_range (single-pass read), forward_range (multi-pass), bidirectional_range, random_access_range, and contiguous_range (elements in contiguous memory). Algorithms and views are constrained by these concepts, so the compiler enforces that a range supports the operations an algorithm needs.
Real-world example A random-access-only algorithm won't compile for a single-pass input range, caught at compile time by concepts.

Common follow-ups: What does random_access_range guarantee? | Why constrain algorithms by range concepts?