From Jason Turner

[range.as.const.overview]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiny8zj7v/{from.md → to.md} +35 -0
tmp/tmpiny8zj7v/{from.md → to.md} RENAMED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Overview <a id="range.as.const.overview">[[range.as.const.overview]]</a>
2
+
3
+ `as_const_view` presents a view of an underlying sequence as constant.
4
+ That is, the elements of an `as_const_view` cannot be modified.
5
+
6
+ The name `views::as_const` denotes a range adaptor object
7
+ [[range.adaptor.object]]. Let `E` be an expression, let `T` be
8
+ `decltype((E))`, and let `U` be `remove_cvref_t<T>`. The expression
9
+ `views::as_const(E)` is expression-equivalent to:
10
+
11
+ - If `views::all_t<T>` models `constant_range`, then `views::all(E)`.
12
+ - Otherwise, if `U` denotes `empty_view<X>` for some type `X`, then
13
+ `auto(views::empty<const X>)`.
14
+ - Otherwise, if `U` denotes `span<X, Extent>` for some type `X` and some
15
+ extent `Extent`, then `span<const X, Extent>(E)`.
16
+ - Otherwise, if `U` denotes `ref_view<X>` for some type `X` and
17
+ `const X` models `constant_range`, then
18
+ `ref_view(static_cast<const X&>(E.base()))`.
19
+ - Otherwise, if `E` is an lvalue, `const U` models `constant_range`, and
20
+ `U` does not model `view`, then `ref_view(static_cast<const U&>(E))`.
21
+ - Otherwise, `as_const_view(E)`.
22
+
23
+ [*Example 1*:
24
+
25
+ ``` cpp
26
+ template<constant_range R>
27
+ void cant_touch_this(R&&);
28
+
29
+ vector<char> hammer = {'m', 'c'};
30
+ span<char> beat = hammer;
31
+ cant_touch_this(views::as_const(beat)); // will not modify the elements of hammer
32
+ ```
33
+
34
+ — *end example*]
35
+