From Jason Turner

[allocator.requirements]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp54msvx41/{from.md → to.md} +52 -47
tmp/tmp54msvx41/{from.md → to.md} RENAMED
@@ -1,32 +1,31 @@
1
- #### Allocator requirements <a id="allocator.requirements">[[allocator.requirements]]</a>
2
 
3
  The library describes a standard set of requirements for *allocators*,
4
  which are class-type objects that encapsulate the information about an
5
  allocation model. This information includes the knowledge of pointer
6
  types, the type of their difference, the type of the size of objects in
7
  this allocation model, as well as the memory allocation and deallocation
8
- primitives for it. All of the string types (Clause  [[strings]]),
9
- containers (Clause  [[containers]]) (except array), string buffers and
10
- string streams (Clause  [[input.output]]), and `match_results` (Clause 
11
- [[re]]) are parameterized in terms of allocators.
12
 
13
- The class template `allocator_traits` ([[allocator.traits]]) supplies a
14
- uniform interface to all allocator types. Table  [[tab:desc.var.def]]
15
- describes the types manipulated through allocators. Table 
16
- [[tab:utilities.allocator.requirements]] describes the requirements on
17
- allocator types and thus on types used to instantiate
18
- `allocator_traits`. A requirement is optional if the last column of
19
- Table  [[tab:utilities.allocator.requirements]] specifies a default for
20
- a given expression. Within the standard library `allocator_traits`
21
- template, an optional requirement that is not supplied by an allocator
22
- is replaced by the specified default expression. A user specialization
23
- of `allocator_traits` may provide different defaults and may provide
24
  defaults for different requirements than the primary template. Within
25
- Tables  [[tab:desc.var.def]] and 
26
- [[tab:utilities.allocator.requirements]], the use of `move` and
27
- `forward` always refers to `std::move` and `std::forward`, respectively.
28
 
29
  [*Note 1*: If `n == 0`, the return value is unspecified. — *end note*]
30
 
31
  Note A: The member class template `rebind` in the table above is
32
  effectively a typedef template.
@@ -42,29 +41,36 @@ and `Allocator` does not supply a `rebind` member template, the standard
42
  `allocator_traits` template uses `SomeAllocator<U, Args>` in place of
43
  `Allocator::{}rebind<U>::other` by default. For allocator types that are
44
  not template instantiations of the above form, no default is provided.
45
 
46
  Note B: If `X::propagate_on_container_copy_assignment::value` is `true`,
47
- `X` shall satisfy the `CopyAssignable` requirements (Table 
48
- [[tab:copyassignable]]) and the copy operation shall not throw
49
  exceptions. If `X::propagate_on_container_move_assignment::value` is
50
- `true`, `X` shall satisfy the `MoveAssignable` requirements (Table 
51
- [[tab:moveassignable]]) and the move operation shall not throw
52
  exceptions. If `X::propagate_on_container_swap::value` is `true`,
53
- lvalues of type `X` shall be swappable ([[swappable.requirements]]) and
54
  the `swap` operation shall not throw exceptions.
55
 
56
- An allocator type `X` shall satisfy the requirements of
57
- `CopyConstructible` ([[utility.arg.requirements]]). The `X::pointer`,
58
  `X::const_pointer`, `X::void_pointer`, and `X::const_void_pointer` types
59
- shall satisfy the requirements of `NullablePointer` (
60
- [[nullablepointer.requirements]]). No constructor, comparison function,
61
- copy operation, move operation, or swap operation on these pointer types
62
  shall exit via an exception. `X::pointer` and `X::const_pointer` shall
63
- also satisfy the requirements for a random access iterator (
64
- [[random.access.iterators]]) and of a contiguous iterator (
65
- [[iterator.requirements.general]]).
 
 
 
 
 
 
 
66
 
67
  Let `x1` and `x2` denote objects of (possibly different) types
68
  `X::void_pointer`, `X::const_void_pointer`, `X::pointer`, or
69
  `X::const_pointer`. Then, `x1` and `x2` are *equivalently-valued*
70
  pointer values, if and only if both `x1` and `x2` can be explicitly
@@ -103,25 +109,32 @@ An allocator may constrain the types on which it can be instantiated and
103
  the arguments for which its `construct` or `destroy` members may be
104
  called. If a type cannot be used with a particular allocator, the
105
  allocator class or the call to `construct` or `destroy` may fail to
106
  instantiate.
107
 
 
 
 
 
 
 
 
 
108
  [*Example 1*:
109
 
110
  The following is an allocator class template supporting the minimal
111
- interface that satisfies the requirements of Table 
112
- [[tab:utilities.allocator.requirements]]:
113
 
114
  ``` cpp
115
  template<class Tp>
116
  struct SimpleAllocator {
117
  typedef Tp value_type;
118
  SimpleAllocator(ctor args);
119
 
120
  template<class T> SimpleAllocator(const SimpleAllocator<T>& other);
121
 
122
- Tp* allocate(std::size_t n);
123
  void deallocate(Tp* p, std::size_t n);
124
  };
125
 
126
  template<class T, class U>
127
  bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
@@ -129,23 +142,15 @@ template <class T, class U>
129
  bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
130
  ```
131
 
132
  — *end example*]
133
 
134
- If the alignment associated with a specific over-aligned type is not
135
- supported by an allocator, instantiation of the allocator for that type
136
- may fail. The allocator also may silently ignore the requested
137
- alignment.
138
-
139
- [*Note 3*: Additionally, the member function `allocate` for that type
140
- may fail by throwing an object of type `bad_alloc`. — *end note*]
141
-
142
  ##### Allocator completeness requirements <a id="allocator.requirements.completeness">[[allocator.requirements.completeness]]</a>
143
 
144
- If `X` is an allocator class for type `T`, `X` additionally satisfies
145
- the allocator completeness requirements if, whether or not `T` is a
146
- complete type:
147
 
148
  - `X` is a complete type, and
149
- - all the member types of `allocator_traits<X>` ([[allocator.traits]])
150
  other than `value_type` are complete types.
151
 
 
1
+ #### *Cpp17Allocator* requirements <a id="allocator.requirements">[[allocator.requirements]]</a>
2
 
3
  The library describes a standard set of requirements for *allocators*,
4
  which are class-type objects that encapsulate the information about an
5
  allocation model. This information includes the knowledge of pointer
6
  types, the type of their difference, the type of the size of objects in
7
  this allocation model, as well as the memory allocation and deallocation
8
+ primitives for it. All of the string types [[strings]], containers
9
+ [[containers]] (except `array`), string buffers and string streams
10
+ [[input.output]], and `match_results` [[re]] are parameterized in terms
11
+ of allocators.
12
 
13
+ The class template `allocator_traits` [[allocator.traits]] supplies a
14
+ uniform interface to all allocator types. [[allocator.req.var]]
15
+ describes the types manipulated through allocators. [[cpp17.allocator]]
16
+ describes the requirements on allocator types and thus on types used to
17
+ instantiate `allocator_traits`. A requirement is optional if the last
18
+ column of [[cpp17.allocator]] specifies a default for a given
19
+ expression. Within the standard library `allocator_traits` template, an
20
+ optional requirement that is not supplied by an allocator is replaced by
21
+ the specified default expression. A user specialization of
22
+ `allocator_traits` may provide different defaults and may provide
 
23
  defaults for different requirements than the primary template. Within
24
+ Tables  [[tab:allocator.req.var]] and  [[tab:cpp17.allocator]], the use
25
+ of `move` and `forward` always refers to `std::move` and `std::forward`,
26
+ respectively.
27
 
28
  [*Note 1*: If `n == 0`, the return value is unspecified. — *end note*]
29
 
30
  Note A: The member class template `rebind` in the table above is
31
  effectively a typedef template.
 
41
  `allocator_traits` template uses `SomeAllocator<U, Args>` in place of
42
  `Allocator::{}rebind<U>::other` by default. For allocator types that are
43
  not template instantiations of the above form, no default is provided.
44
 
45
  Note B: If `X::propagate_on_container_copy_assignment::value` is `true`,
46
+ `X` shall meet the *Cpp17CopyAssignable* requirements (
47
+ [[cpp17.copyassignable]]) and the copy operation shall not throw
48
  exceptions. If `X::propagate_on_container_move_assignment::value` is
49
+ `true`, `X` shall meet the *Cpp17MoveAssignable* requirements (
50
+ [[cpp17.moveassignable]]) and the move operation shall not throw
51
  exceptions. If `X::propagate_on_container_swap::value` is `true`,
52
+ lvalues of type `X` shall be swappable [[swappable.requirements]] and
53
  the `swap` operation shall not throw exceptions.
54
 
55
+ An allocator type `X` shall meet the *Cpp17CopyConstructible*
56
+ requirements ([[cpp17.copyconstructible]]). The `X::pointer`,
57
  `X::const_pointer`, `X::void_pointer`, and `X::const_void_pointer` types
58
+ shall meet the *Cpp17NullablePointer* requirements (
59
+ [[cpp17.nullablepointer]]). No constructor, comparison function, copy
60
+ operation, move operation, or swap operation on these pointer types
61
  shall exit via an exception. `X::pointer` and `X::const_pointer` shall
62
+ also meet the requirements for a *Cpp17RandomAccessIterator*
63
+ [[random.access.iterators]] and the additional requirement that, when
64
+ `a` and `(a + n)` are dereferenceable pointer values for some integral
65
+ value `n`,
66
+
67
+ ``` cpp
68
+ addressof(*(a + n)) == addressof(*a) + n
69
+ ```
70
+
71
+ is `true`.
72
 
73
  Let `x1` and `x2` denote objects of (possibly different) types
74
  `X::void_pointer`, `X::const_void_pointer`, `X::pointer`, or
75
  `X::const_pointer`. Then, `x1` and `x2` are *equivalently-valued*
76
  pointer values, if and only if both `x1` and `x2` can be explicitly
 
109
  the arguments for which its `construct` or `destroy` members may be
110
  called. If a type cannot be used with a particular allocator, the
111
  allocator class or the call to `construct` or `destroy` may fail to
112
  instantiate.
113
 
114
+ If the alignment associated with a specific over-aligned type is not
115
+ supported by an allocator, instantiation of the allocator for that type
116
+ may fail. The allocator also may silently ignore the requested
117
+ alignment.
118
+
119
+ [*Note 3*: Additionally, the member function `allocate` for that type
120
+ may fail by throwing an object of type `bad_alloc`. — *end note*]
121
+
122
  [*Example 1*:
123
 
124
  The following is an allocator class template supporting the minimal
125
+ interface that meets the requirements of [[cpp17.allocator]]:
 
126
 
127
  ``` cpp
128
  template<class Tp>
129
  struct SimpleAllocator {
130
  typedef Tp value_type;
131
  SimpleAllocator(ctor args);
132
 
133
  template<class T> SimpleAllocator(const SimpleAllocator<T>& other);
134
 
135
+ [[nodiscard]] Tp* allocate(std::size_t n);
136
  void deallocate(Tp* p, std::size_t n);
137
  };
138
 
139
  template<class T, class U>
140
  bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
 
142
  bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
143
  ```
144
 
145
  — *end example*]
146
 
 
 
 
 
 
 
 
 
147
  ##### Allocator completeness requirements <a id="allocator.requirements.completeness">[[allocator.requirements.completeness]]</a>
148
 
149
+ If `X` is an allocator class for type `T`, `X` additionally meets the
150
+ allocator completeness requirements if, whether or not `T` is a complete
151
+ type:
152
 
153
  - `X` is a complete type, and
154
+ - all the member types of `allocator_traits<X>` [[allocator.traits]]
155
  other than `value_type` are complete types.
156