From Jason Turner

[mem.poly.allocator.mem]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp7erteob1/{from.md → to.md} +88 -115
tmp/tmp7erteob1/{from.md → to.md} RENAMED
@@ -1,150 +1,123 @@
1
- #### `polymorphic_allocator` member functions <a id="mem.poly.allocator.mem">[[mem.poly.allocator.mem]]</a>
2
 
3
  ``` cpp
4
- Tp* allocate(size_t n);
5
  ```
6
 
7
- *Returns:* Equivalent to
 
8
 
9
  ``` cpp
10
  return static_cast<Tp*>(memory_rsrc->allocate(n * sizeof(Tp), alignof(Tp)));
11
  ```
12
 
13
  ``` cpp
14
  void deallocate(Tp* p, size_t n);
15
  ```
16
 
17
- *Requires:* `p` was allocated from a memory resource `x`, equal to
18
  `*memory_rsrc`, using `x.allocate(n * sizeof(Tp), alignof(Tp))`.
19
 
20
  *Effects:* Equivalent to
21
  `memory_rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp))`.
22
 
23
  *Throws:* Nothing.
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ``` cpp
26
  template<class T, class... Args>
27
  void construct(T* p, Args&&... args);
28
  ```
29
 
30
- *Requires:* Uses-allocator construction of `T` with allocator
31
- `resource()` (see  [[allocator.uses.construction]]) and constructor
32
- arguments `std::forward<Args>(args)...` is well-formed.
33
-
34
- [*Note 1*: Uses-allocator construction is always well formed for types
35
- that do not use allocators. — *end note*]
36
 
37
  *Effects:* Construct a `T` object in the storage whose address is
38
- represented by `p` by uses-allocator construction with allocator
39
- `resource()` and constructor arguments `std::forward<Args>(args)...`.
40
 
41
  *Throws:* Nothing unless the constructor for `T` throws.
42
 
43
- ``` cpp
44
- template <class T1, class T2, class... Args1, class... Args2>
45
- void construct(pair<T1,T2>* p, piecewise_construct_t,
46
- tuple<Args1...> x, tuple<Args2...> y);
47
- ```
48
-
49
- [*Note 2*: This method and the `construct` methods that follow are
50
- overloads for piecewise construction of
51
- pairs ([[pairs.pair]]). — *end note*]
52
-
53
- *Effects:* Let `xprime` be a `tuple` constructed from `x` according to
54
- the appropriate rule from the following list.
55
-
56
- [*Note 3*: The following description can be summarized as constructing
57
- a `pair<T1, T2>` object in the storage whose address is represented by
58
- `p`, as if by separate uses-allocator construction with allocator
59
- `resource()` ([[allocator.uses.construction]]) of `p->first` using the
60
- elements of `x` and `p->second` using the elements of
61
- `y`. — *end note*]
62
-
63
- - If `uses_allocator_v<T1,memory_resource*>` is `false`
64
- and `is_constructible_v<T1,Args1...>` is `true`,
65
- then `xprime` is `x`.
66
- - Otherwise, if `uses_allocator_v<T1,memory_resource*>` is `true`
67
- and `is_constructible_v<T1,allocator_arg_t,memory_resource*,Args1...>`
68
- is `true`,
69
- then `xprime` is
70
- `tuple_cat(make_tuple(allocator_arg, resource()), std::move(x))`.
71
- - Otherwise, if `uses_allocator_v<T1,memory_resource*>` is `true`
72
- and `is_constructible_v<T1,Args1...,memory_resource*>` is `true`,
73
- then `xprime` is `tuple_cat(std::move(x), make_tuple(resource()))`.
74
- - Otherwise the program is ill formed.
75
-
76
- Let `yprime` be a tuple constructed from `y` according to the
77
- appropriate rule from the following list:
78
-
79
- - If `uses_allocator_v<T2,memory_resource*>` is `false`
80
- and `is_constructible_v<T2,Args2...>` is `true`,
81
- then `yprime` is `y`.
82
- - Otherwise, if `uses_allocator_v<T2,memory_resource*>` is `true`
83
- and `is_constructible_v<T2,allocator_arg_t,memory_resource*,Args2...>`
84
- is `true`,
85
- then `yprime` is
86
- `tuple_cat(make_tuple(allocator_arg, resource()), std::move(y))`.
87
- - Otherwise, if `uses_allocator_v<T2,memory_resource*>` is `true`
88
- and `is_constructible_v<T2,Args2...,memory_resource*>` is `true`,
89
- then `yprime` is `tuple_cat(std::move(y), make_tuple(resource()))`.
90
- - Otherwise the program is ill formed.
91
-
92
- Then, using `piecewise_construct`, `xprime`, and `yprime` as the
93
- constructor arguments, this function constructs a `pair<T1, T2>` object
94
- in the storage whose address is represented by `p`.
95
-
96
- ``` cpp
97
- template <class T1, class T2>
98
- void construct(pair<T1,T2>* p);
99
- ```
100
-
101
- *Effects:* Equivalent to:
102
-
103
- ``` cpp
104
- construct(p, piecewise_construct, tuple<>(), tuple<>());
105
- ```
106
-
107
- ``` cpp
108
- template <class T1, class T2, class U, class V>
109
- void construct(pair<T1,T2>* p, U&& x, V&& y);
110
- ```
111
-
112
- *Effects:* Equivalent to:
113
-
114
- ``` cpp
115
- construct(p, piecewise_construct,
116
- forward_as_tuple(std::forward<U>(x)),
117
- forward_as_tuple(std::forward<V>(y)));
118
- ```
119
-
120
- ``` cpp
121
- template <class T1, class T2, class U, class V>
122
- void construct(pair<T1,T2>* p, const pair<U, V>& pr);
123
- ```
124
-
125
- *Effects:* Equivalent to:
126
-
127
- ``` cpp
128
- construct(p, piecewise_construct,
129
- forward_as_tuple(pr.first),
130
- forward_as_tuple(pr.second));
131
- ```
132
-
133
- ``` cpp
134
- template <class T1, class T2, class U, class V>
135
- void construct(pair<T1,T2>* p, pair<U, V>&& pr);
136
- ```
137
-
138
- *Effects:* Equivalent to:
139
-
140
- ``` cpp
141
- construct(p, piecewise_construct,
142
- forward_as_tuple(std::forward<U>(pr.first)),
143
- forward_as_tuple(std::forward<V>(pr.second)));
144
- ```
145
-
146
  ``` cpp
147
  template<class T>
148
  void destroy(T* p);
149
  ```
150
 
 
1
+ #### Member functions <a id="mem.poly.allocator.mem">[[mem.poly.allocator.mem]]</a>
2
 
3
  ``` cpp
4
+ [[nodiscard]] Tp* allocate(size_t n);
5
  ```
6
 
7
+ *Effects:* If `numeric_limits<size_t>::max() / sizeof(Tp) < n`, throws
8
+ `bad_array_new_length`. Otherwise equivalent to:
9
 
10
  ``` cpp
11
  return static_cast<Tp*>(memory_rsrc->allocate(n * sizeof(Tp), alignof(Tp)));
12
  ```
13
 
14
  ``` cpp
15
  void deallocate(Tp* p, size_t n);
16
  ```
17
 
18
+ *Preconditions:* `p` was allocated from a memory resource `x`, equal to
19
  `*memory_rsrc`, using `x.allocate(n * sizeof(Tp), alignof(Tp))`.
20
 
21
  *Effects:* Equivalent to
22
  `memory_rsrc->deallocate(p, n * sizeof(Tp), alignof(Tp))`.
23
 
24
  *Throws:* Nothing.
25
 
26
+ ``` cpp
27
+ [[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
28
+ ```
29
+
30
+ *Effects:* Equivalent to:
31
+ `return memory_rsrc->allocate(nbytes, alignment);`
32
+
33
+ [*Note 1*: The return type is `void*` (rather than, e.g., `byte*`) to
34
+ support conversion to an arbitrary pointer type `U*` by
35
+ `static_cast<U*>`, thus facilitating construction of a `U` object in the
36
+ allocated memory. — *end note*]
37
+
38
+ ``` cpp
39
+ void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t));
40
+ ```
41
+
42
+ *Effects:* Equivalent to
43
+ `memory_rsrc->deallocate(p, nbytes, alignment)`.
44
+
45
+ ``` cpp
46
+ template<class T>
47
+ [[nodiscard]] T* allocate_object(size_t n = 1);
48
+ ```
49
+
50
+ *Effects:* Allocates memory suitable for holding an array of `n` objects
51
+ of type `T`, as follows:
52
+
53
+ - if `numeric_limits<size_t>::max() / sizeof(T) < n`, throws
54
+ `bad_array_new_length`,
55
+ - otherwise equivalent to:
56
+ ``` cpp
57
+ return static_cast<T*>(allocate_bytes(n*sizeof(T), alignof(T)));
58
+ ```
59
+
60
+ [*Note 2*: `T` is not deduced and must therefore be provided as a
61
+ template argument. — *end note*]
62
+
63
+ ``` cpp
64
+ template<class T>
65
+ void deallocate_object(T* p, size_t n = 1);
66
+ ```
67
+
68
+ *Effects:* Equivalent to `deallocate_bytes(p, n*sizeof(T), alignof(T))`.
69
+
70
+ ``` cpp
71
+ template<class T, class CtorArgs...>
72
+ [[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
73
+ ```
74
+
75
+ *Effects:* Allocates and constructs an object of type `T`, as follows.
76
+ Equivalent to:
77
+
78
+ ``` cpp
79
+ T* p = allocate_object<T>();
80
+ try {
81
+ construct(p, std::forward<CtorArgs>(ctor_args)...);
82
+ } catch (...) {
83
+ deallocate_object(p);
84
+ throw;
85
+ }
86
+ return p;
87
+ ```
88
+
89
+ [*Note 3*: `T` is not deduced and must therefore be provided as a
90
+ template argument. — *end note*]
91
+
92
+ ``` cpp
93
+ template<class T>
94
+ void delete_object(T* p);
95
+ ```
96
+
97
+ *Effects:* Equivalent to:
98
+
99
+ ``` cpp
100
+ destroy(p);
101
+ deallocate_object(p);
102
+ ```
103
+
104
  ``` cpp
105
  template<class T, class... Args>
106
  void construct(T* p, Args&&... args);
107
  ```
108
 
109
+ *Mandates:* Uses-allocator construction of `T` with allocator `*this`
110
+ (see  [[allocator.uses.construction]]) and constructor arguments
111
+ `std::forward<Args>(args)...` is well-formed.
 
 
 
112
 
113
  *Effects:* Construct a `T` object in the storage whose address is
114
+ represented by `p` by uses-allocator construction with allocator `*this`
115
+ and constructor arguments `std::forward<Args>(args)...`.
116
 
117
  *Throws:* Nothing unless the constructor for `T` throws.
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  ``` cpp
120
  template<class T>
121
  void destroy(T* p);
122
  ```
123