From Jason Turner

[range.range]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp6hvwqcvu/{from.md → to.md} +76 -0
tmp/tmp6hvwqcvu/{from.md → to.md} RENAMED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Ranges <a id="range.range">[[range.range]]</a>
2
+
3
+ The `range` concept defines the requirements of a type that allows
4
+ iteration over its elements by providing an iterator and sentinel that
5
+ denote the elements of the range.
6
+
7
+ ``` cpp
8
+ template<class T>
9
+ concept range =
10
+ requires(T& t) {
11
+ ranges::begin(t); // sometimes equality-preserving (see below)
12
+ ranges::end(t);
13
+ };
14
+ ```
15
+
16
+ The required expressions `ranges::begin(t)` and `ranges::end(t)` of the
17
+ `range` concept do not require implicit expression
18
+ variations [[concepts.equality]].
19
+
20
+ Given an expression `t` such that `decltype((t))` is `T&`, `T` models
21
+ `range` only if
22
+
23
+ - \[`ranges::begin(t)`, `ranges::end(t)`) denotes a
24
+ range [[iterator.requirements.general]],
25
+ - both `ranges::begin(t)` and `ranges::end(t)` are amortized constant
26
+ time and non-modifying, and
27
+ - if the type of `ranges::begin(t)` models `forward_iterator`,
28
+ `ranges::begin(t)` is equality-preserving.
29
+
30
+ [*Note 1*: Equality preservation of both `ranges::begin` and
31
+ `ranges::end` enables passing a `range` whose iterator type models
32
+ `forward_iterator` to multiple algorithms and making multiple passes
33
+ over the range by repeated calls to `ranges::begin` and `ranges::end`.
34
+ Since `ranges::begin` is not required to be equality-preserving when the
35
+ return type does not model `forward_iterator`, repeated calls might not
36
+ return equal values or might not be well-defined; `ranges::begin` should
37
+ be called at most once for such a range. — *end note*]
38
+
39
+ ``` cpp
40
+ template<class T>
41
+ concept borrowed_range =
42
+ range<T> &&
43
+ (is_lvalue_reference_v<T> || enable_borrowed_range<remove_cvref_t<T>>);
44
+ ```
45
+
46
+ Given an expression `E` such that `decltype((E))` is `T`, `T` models
47
+ `borrowed_range` only if the validity of iterators obtained from the
48
+ object denoted by `E` is not tied to the lifetime of that object.
49
+
50
+ [*Note 2*: Since the validity of iterators is not tied to the lifetime
51
+ of an object whose type models `borrowed_range`, a function can accept
52
+ arguments of such a type by value and return iterators obtained from it
53
+ without danger of dangling. — *end note*]
54
+
55
+ ``` cpp
56
+ template<class>
57
+ inline constexpr bool enable_borrowed_range = false;
58
+ ```
59
+
60
+ *Remarks:* Pursuant to [[namespace.std]], users may specialize
61
+ `enable_borrowed_range` for cv-unqualified program-defined types. Such
62
+ specializations shall be usable in constant expressions [[expr.const]]
63
+ and have type `const bool`.
64
+
65
+ [*Example 1*:
66
+
67
+ Each specialization `S` of class template `subrange` [[range.subrange]]
68
+ models `borrowed_range` because
69
+
70
+ - `enable_borrowed_range<S>` is specialized to have the value `true`,
71
+ and
72
+ - `S`’s iterators do not have validity tied to the lifetime of an `S`
73
+ object because they are “borrowed” from some other range.
74
+
75
+ — *end example*]
76
+