[range.common.overview]

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

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.common.overview)

### 25.7.20 Common view [[range.common]](range.common#overview)

#### 25.7.20.1 Overview [range.common.overview]

[1](#1)

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

common_view takes a view which has different types for
its iterator and sentinel and turns it into a view of the same
elements with an iterator and sentinel of the same type[.](#1.sentence-1)

[2](#2)

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

[*Note [1](#note-1)*:

common_view is useful for calling legacy algorithms that expect
a range's iterator and sentinel types to be the same[.](#2.sentence-1)

â *end note*]

[3](#3)

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

The name views​::​common denotes a
range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#3.sentence-1)

Given a subexpression E,
the expression views​::​common(E) is expression-equivalent to:

- [(3.1)](#3.1)

  views​::​all(E),
 if decltype((E)) models [common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]") and views​::​all(E) is a well-formed expression[.](#3.1.sentence-1)

- [(3.2)](#3.2)

  Otherwise, common_view{E}[.](#3.2.sentence-1)

[4](#4)

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

[*Example [1](#example-1)*: // Legacy algorithm:template<class ForwardIterator> size_t count(ForwardIterator first, ForwardIterator last);

template<[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") R>void my_algo(R&& r) {auto&& common = views::common(r); auto cnt = count(common.begin(), common.end()); // ...} â *end example*]
