From Jason Turner

[range.common.overview]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpu_s4qnid/{from.md → to.md} +35 -0
tmp/tmpu_s4qnid/{from.md → to.md} RENAMED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Overview <a id="range.common.overview">[[range.common.overview]]</a>
2
+
3
+ `common_view` takes a `view` which has different types for its iterator
4
+ and sentinel and turns it into a `view` of the same elements with an
5
+ iterator and sentinel of the same type.
6
+
7
+ [*Note 1*: `common_view` is useful for calling legacy algorithms that
8
+ expect a range’s iterator and sentinel types to be the
9
+ same. — *end note*]
10
+
11
+ The name `views::common` denotes a range adaptor object
12
+ [[range.adaptor.object]]. Given a subexpression `E`, the expression
13
+ `views::common(E)` is expression-equivalent to:
14
+
15
+ - `views::all(E)`, if `decltype((E))` models `common_range` and
16
+ `views::all(E)` is a well-formed expression.
17
+ - Otherwise, `common_view{E}`.
18
+
19
+ [*Example 1*:
20
+
21
+ ``` cpp
22
+ // Legacy algorithm:
23
+ template<class ForwardIterator>
24
+ size_t count(ForwardIterator first, ForwardIterator last);
25
+
26
+ template<forward_range R>
27
+ void my_algo(R&& r) {
28
+ auto&& common = common_view{r};
29
+ auto cnt = count(common.begin(), common.end());
30
+ // ...
31
+ }
32
+ ```
33
+
34
+ — *end example*]
35
+