From Jason Turner

[range.view]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp3o0a99gs/{from.md → to.md} +26 -11
tmp/tmp3o0a99gs/{from.md → to.md} RENAMED
@@ -1,49 +1,64 @@
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`.
 
1
  ### Views <a id="range.view">[[range.view]]</a>
2
 
3
  The `view` concept specifies the requirements of a `range` type that has
4
+ the semantic properties below, which make it suitable for use in
5
+ constructing range adaptor pipelines [[range.adaptors]].
 
6
 
7
  ``` cpp
8
  template<class T>
9
  concept view =
10
+ range<T> && movable<T> && enable_view<T>;
11
  ```
12
 
13
  `T` models `view` only if:
14
 
15
  - `T` has 𝑂(1) move construction; and
16
+ - move assignment of an object of type `T` is no more complex than
17
+ destruction followed by move construction; and
18
+ - if N copies and/or moves are made from an object of type `T` that
19
+ contained M elements, then those N objects have 𝑂(N+M) destruction;
20
+ and
21
  - `copy_constructible<T>` is `false`, or `T` has 𝑂(1) copy construction;
22
  and
23
+ - `copyable<T>` is `false`, or copy assignment of an object of type `T`
24
+ is no more complex than destruction followed by copy construction.
25
+
26
+ [*Note 1*: The constraints on copying and moving imply that a
27
+ moved-from object of type `T` has 𝑂(1) destruction. — *end note*]
28
 
29
  [*Example 1*:
30
 
31
+ Examples of views are:
32
 
33
  - A `range` type that wraps a pair of iterators.
34
  - A `range` type that holds its elements by `shared_ptr` and shares
35
  ownership with all its copies.
36
  - A `range` type that generates its elements on demand.
37
 
38
+ A container such as `vector<string>` does not meet the semantic
39
+ requirements of `view` since copying the container copies all of the
40
+ elements, which cannot be done in constant time.
41
 
42
  — *end example*]
43
 
44
  Since the difference between `range` and `view` is largely semantic, the
45
  two are differentiated with the help of `enable_view`.
46
 
47
  ``` cpp
48
  template<class T>
49
+ constexpr bool is-derived-from-view-interface = see belownc; // exposition only
50
+ template<class T>
51
+ constexpr bool enable_view =
52
+ derived_from<T, view_base> || is-derived-from-view-interface<T>;
53
  ```
54
 
55
+ For a type `T`, *`is-derived-from-view-interface`*`<T>` is `true` if and
56
+ only if `T` has exactly one public base class `view_interface<U>` for
57
+ some type `U` and `T` has no base classes of type `view_interface<V>`
58
+ for any other type `V`.
59
+
60
  *Remarks:* Pursuant to [[namespace.std]], users may specialize
61
  `enable_view` to `true` for cv-unqualified program-defined types which
62
  model `view`, and `false` for types which do not. Such specializations
63
  shall be usable in constant expressions [[expr.const]] and have type
64
  `const bool`.