From Jason Turner

[range.elementsof]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpmcnl4t1_/{from.md → to.md} +33 -0
tmp/tmpmcnl4t1_/{from.md → to.md} RENAMED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class template `elements_of` <a id="range.elementsof">[[range.elementsof]]</a>
2
+
3
+ Specializations of `elements_of` encapsulate a range and act as a tag in
4
+ overload sets to disambiguate when a range should be treated as a
5
+ sequence rather than a single value.
6
+
7
+ [*Example 1*:
8
+
9
+ ``` cpp
10
+ template<bool YieldElements>
11
+ generator<any> f(ranges::input_range auto&& r) {
12
+ if constexpr (YieldElements)
13
+ co_yield ranges::elements_of(r); // yield each element of r
14
+ else
15
+ co_yield r; // yield r as a single value
16
+ }
17
+ ```
18
+
19
+ — *end example*]
20
+
21
+ ``` cpp
22
+ namespace std::ranges {
23
+ template<range R, class Allocator = allocator<byte>>
24
+ struct elements_of {
25
+ [[no_unique_address]] R range;
26
+ [[no_unique_address]] Allocator allocator = Allocator();
27
+ };
28
+
29
+ template<class R, class Allocator = allocator<byte>>
30
+ elements_of(R&&, Allocator = Allocator()) -> elements_of<R&&, Allocator>;
31
+ }
32
+ ```
33
+