52 lines
2.1 KiB
Markdown
52 lines
2.1 KiB
Markdown
[range.counted]
|
||
|
||
# 25 Ranges library [[ranges]](./#ranges)
|
||
|
||
## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.counted)
|
||
|
||
### 25.7.19 Counted view [range.counted]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L9712)
|
||
|
||
A counted view presents a view of the elements
|
||
of the counted range ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General")) i+[0, n) for an iterator i and non-negative integer n[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L9718)
|
||
|
||
The name views::counted denotes
|
||
a customization point object ([[customization.point.object]](customization.point.object "16.3.3.3.5 Customization Point Object types"))[.](#2.sentence-1)
|
||
|
||
Let E and F be expressions,
|
||
let T be decay_t<decltype((E))>, and
|
||
let D be iter_difference_t<T>[.](#2.sentence-2)
|
||
|
||
If decltype((F)) does not model[convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_to [concept.convertible]")<D>,views::counted(E, F) is ill-formed[.](#2.sentence-3)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
This case can result in substitution failure
|
||
when views::counted(E, F) appears in the immediate context of a template instantiation[.](#2.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
Otherwise, views::counted(E, F) is expression-equivalent to:
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
If T models [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_iterator [iterator.concept.contiguous]"),
|
||
then span(to_address(E), static_cast<size_t>(static_cast<D>(F)))[.](#2.1.sentence-1)
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
Otherwise, if T models [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_access_iterator [iterator.concept.random.access]"),
|
||
then subrange(E, E + static_cast<D>(F)),
|
||
except that E is evaluated only once[.](#2.2.sentence-1)
|
||
|
||
- [(2.3)](#2.3)
|
||
|
||
Otherwise,subrange(counted_iterator(E, F), default_sentinel)[.](#2.3.sentence-1)
|