tmp/tmp5hir4r7n/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Views <a id="range.view">[[range.view]]</a>
|
| 2 |
+
|
| 3 |
+
The `view` concept specifies the requirements of a `range` type that has
|
| 4 |
+
constant time move construction, move assignment, and destruction; that
|
| 5 |
+
is, the cost of these operations is independent of the number of
|
| 6 |
+
elements in the `view`.
|
| 7 |
+
|
| 8 |
+
``` cpp
|
| 9 |
+
template<class T>
|
| 10 |
+
concept view =
|
| 11 |
+
range<T> && movable<T> && default_initializable<T> && enable_view<T>;
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
`T` models `view` only if:
|
| 15 |
+
|
| 16 |
+
- `T` has 𝑂(1) move construction; and
|
| 17 |
+
- `T` has 𝑂(1) move assignment; and
|
| 18 |
+
- `T` has 𝑂(1) destruction; and
|
| 19 |
+
- `copy_constructible<T>` is `false`, or `T` has 𝑂(1) copy construction;
|
| 20 |
+
and
|
| 21 |
+
- `copyable<T>` is `false`, or `T` has 𝑂(1) copy assignment.
|
| 22 |
+
|
| 23 |
+
[*Example 1*:
|
| 24 |
+
|
| 25 |
+
Examples of `view`s are:
|
| 26 |
+
|
| 27 |
+
- A `range` type that wraps a pair of iterators.
|
| 28 |
+
- A `range` type that holds its elements by `shared_ptr` and shares
|
| 29 |
+
ownership with all its copies.
|
| 30 |
+
- A `range` type that generates its elements on demand.
|
| 31 |
+
|
| 32 |
+
Most containers [[containers]] are not views since destruction of the
|
| 33 |
+
container destroys the elements, which cannot be done in constant time.
|
| 34 |
+
|
| 35 |
+
— *end example*]
|
| 36 |
+
|
| 37 |
+
Since the difference between `range` and `view` is largely semantic, the
|
| 38 |
+
two are differentiated with the help of `enable_view`.
|
| 39 |
+
|
| 40 |
+
``` cpp
|
| 41 |
+
template<class T>
|
| 42 |
+
inline constexpr bool enable_view = derived_from<T, view_base>;
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
*Remarks:* Pursuant to [[namespace.std]], users may specialize
|
| 46 |
+
`enable_view` to `true` for cv-unqualified program-defined types which
|
| 47 |
+
model `view`, and `false` for types which do not. Such specializations
|
| 48 |
+
shall be usable in constant expressions [[expr.const]] and have type
|
| 49 |
+
`const bool`.
|
| 50 |
+
|