51 lines
1.8 KiB
Markdown
51 lines
1.8 KiB
Markdown
[range.adjacent.overview]
|
||
|
||
# 25 Ranges library [[ranges]](./#ranges)
|
||
|
||
## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.adjacent.overview)
|
||
|
||
### 25.7.27 Adjacent view [[range.adjacent]](range.adjacent#overview)
|
||
|
||
#### 25.7.27.1 Overview [range.adjacent.overview]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12539)
|
||
|
||
adjacent_view takes a view and
|
||
produces a view whose Mth element is
|
||
a tuple of references to
|
||
the Mth through (M+Nâ1)th elements of
|
||
the original view[.](#1.sentence-1)
|
||
|
||
If the original view has fewer than N elements, the resulting view is empty[.](#1.sentence-2)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12547)
|
||
|
||
The name views::adjacent<N> denotes
|
||
a range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#2.sentence-1)
|
||
|
||
Given a subexpression E and a constant expression N,
|
||
the expression views::adjacent<N>(E) is expression-equivalent to
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
((void)E, auto(views::empty<tuple<>>)) if N is equal to 0 anddecltype((E)) models [forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]"),
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
otherwise, adjacent_view<views::all_t<decltype((E))>, N>(E)[.](#2.sentence-2)
|
||
|
||
[*Example [1](#example-1)*: vector v = {1, 2, 3, 4};
|
||
|
||
for (auto i : v | views::adjacent<2>) { cout << "(" << std::get<0>(i) << ", " << std::get<1>(i) << ") "; // prints (1, 2) (2, 3) (3, 4)} â *end example*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L12572)
|
||
|
||
Define *REPEAT*(T, N) as a pack of N types,
|
||
each of which denotes the same type as T[.](#3.sentence-1)
|