[range.req.general]

# 25 Ranges library [[ranges]](./#ranges)

## 25.4 Range requirements [[range.req]](range.req#general)

### 25.4.1 General [range.req.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1287)

Ranges are an abstraction that allows a C++ program
to operate on elements of data structures uniformly[.](#1.sentence-1)

Calling ranges​::​begin on a range returns an object
whose type models [input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") ([[iterator.concept.iterator]](iterator.concept.iterator "24.3.4.6 Concept input_­or_­output_­iterator"))[.](#1.sentence-2)

Calling ranges​::​end on a range returns an object whose type S,
together with the type I of the object returned by ranges​::​begin,
models [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<S, I>[.](#1.sentence-3)

The library formalizes the interfaces, semantics, and complexity of ranges
to enable algorithms and range adaptors that work efficiently
on different types of sequences[.](#1.sentence-4)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1299)

The [range](range.range#concept:range "25.4.2 Ranges [range.range]") concept requires thatranges​::​begin and ranges​::​end return an iterator and a sentinel, respectively[.](#2.sentence-1)

The [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]") concept refines [range](range.range#concept:range "25.4.2 Ranges [range.range]") with
the requirement that ranges​::​size be amortized O(1)[.](#2.sentence-2)

The [view](range.view#concept:view "25.4.5 Views [range.view]") concept specifies requirements on
a [range](range.range#concept:range "25.4.2 Ranges [range.range]") type to provide operations with predictable complexity[.](#2.sentence-3)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L1308)

Several refinements of [range](range.range#concept:range "25.4.2 Ranges [range.range]") group requirements
that arise frequently in concepts and algorithms[.](#3.sentence-1)

Common ranges are ranges for whichranges​::​begin and ranges​::​end return objects of the same type[.](#3.sentence-2)

Random access ranges are ranges for which ranges​::​begin returns a type that models[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]") ([[iterator.concept.random.access]](iterator.concept.random.access "24.3.4.13 Concept random_­access_­iterator"))[.](#3.sentence-3)

(Contiguous, bidirectional, forward, input, and output ranges
are defined similarly[.](#3.sentence-4))

Viewable ranges can be converted to views[.](#3.sentence-5)
