tmp/tmps4aypen4/{from.md → to.md}
RENAMED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
### The default allocator <a id="default.allocator">[[default.allocator]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
All specializations of the default allocator meet the allocator
|
| 4 |
completeness requirements [[allocator.requirements.completeness]].
|
| 5 |
|
| 6 |
``` cpp
|
| 7 |
namespace std {
|
|
@@ -9,24 +11,28 @@ namespace std {
|
|
| 9 |
public:
|
| 10 |
using value_type = T;
|
| 11 |
using size_type = size_t;
|
| 12 |
using difference_type = ptrdiff_t;
|
| 13 |
using propagate_on_container_move_assignment = true_type;
|
| 14 |
-
using is_always_equal = true_type;
|
| 15 |
|
| 16 |
constexpr allocator() noexcept;
|
| 17 |
constexpr allocator(const allocator&) noexcept;
|
| 18 |
template<class U> constexpr allocator(const allocator<U>&) noexcept;
|
| 19 |
constexpr ~allocator();
|
| 20 |
constexpr allocator& operator=(const allocator&) = default;
|
| 21 |
|
| 22 |
[[nodiscard]] constexpr T* allocate(size_t n);
|
|
|
|
| 23 |
constexpr void deallocate(T* p, size_t n);
|
| 24 |
};
|
| 25 |
}
|
| 26 |
```
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
#### Members <a id="allocator.members">[[allocator.members]]</a>
|
| 29 |
|
| 30 |
Except for the destructor, member functions of the default allocator
|
| 31 |
shall not introduce data races [[intro.multithread]] as a result of
|
| 32 |
concurrent calls to those member functions from different threads. Calls
|
|
@@ -36,30 +42,54 @@ call shall happen before the next allocation (if any) in this order.
|
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
[[nodiscard]] constexpr T* allocate(size_t n);
|
| 39 |
```
|
| 40 |
|
| 41 |
-
*Mandates:* `T` is not an incomplete type [[
|
| 42 |
|
| 43 |
*Returns:* A pointer to the initial element of an array of `n` `T`.
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
*Remarks:* The storage for the array is obtained by calling
|
| 46 |
`::operator new` [[new.delete]], but it is unspecified when or how often
|
| 47 |
this function is called. This function starts the lifetime of the array
|
| 48 |
object, but not that of any of the array elements.
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
*Throws:* `bad_array_new_length` if
|
| 51 |
-
`numeric_limits<size_t>::max() / sizeof(T) < n`, or `bad_alloc` if the
|
| 52 |
storage cannot be obtained.
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
``` cpp
|
| 55 |
constexpr void deallocate(T* p, size_t n);
|
| 56 |
```
|
| 57 |
|
| 58 |
-
*Preconditions:*
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
*Effects:* Deallocates the storage referenced by `p`.
|
| 63 |
|
| 64 |
*Remarks:* Uses `::operator delete` [[new.delete]], but it is
|
| 65 |
unspecified when this function is called.
|
|
|
|
| 1 |
### The default allocator <a id="default.allocator">[[default.allocator]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="default.allocator.general">[[default.allocator.general]]</a>
|
| 4 |
+
|
| 5 |
All specializations of the default allocator meet the allocator
|
| 6 |
completeness requirements [[allocator.requirements.completeness]].
|
| 7 |
|
| 8 |
``` cpp
|
| 9 |
namespace std {
|
|
|
|
| 11 |
public:
|
| 12 |
using value_type = T;
|
| 13 |
using size_type = size_t;
|
| 14 |
using difference_type = ptrdiff_t;
|
| 15 |
using propagate_on_container_move_assignment = true_type;
|
|
|
|
| 16 |
|
| 17 |
constexpr allocator() noexcept;
|
| 18 |
constexpr allocator(const allocator&) noexcept;
|
| 19 |
template<class U> constexpr allocator(const allocator<U>&) noexcept;
|
| 20 |
constexpr ~allocator();
|
| 21 |
constexpr allocator& operator=(const allocator&) = default;
|
| 22 |
|
| 23 |
[[nodiscard]] constexpr T* allocate(size_t n);
|
| 24 |
+
[[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n);
|
| 25 |
constexpr void deallocate(T* p, size_t n);
|
| 26 |
};
|
| 27 |
}
|
| 28 |
```
|
| 29 |
|
| 30 |
+
`allocator_traits<allocator<T>>::is_always_equal::value`
|
| 31 |
+
|
| 32 |
+
is `true` for any `T`.
|
| 33 |
+
|
| 34 |
#### Members <a id="allocator.members">[[allocator.members]]</a>
|
| 35 |
|
| 36 |
Except for the destructor, member functions of the default allocator
|
| 37 |
shall not introduce data races [[intro.multithread]] as a result of
|
| 38 |
concurrent calls to those member functions from different threads. Calls
|
|
|
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
[[nodiscard]] constexpr T* allocate(size_t n);
|
| 45 |
```
|
| 46 |
|
| 47 |
+
*Mandates:* `T` is not an incomplete type [[term.incomplete.type]].
|
| 48 |
|
| 49 |
*Returns:* A pointer to the initial element of an array of `n` `T`.
|
| 50 |
|
| 51 |
+
*Throws:* `bad_array_new_length` if
|
| 52 |
+
`numeric_limits<size_t>::max() / sizeof(T) < n`, or `bad_alloc` if the
|
| 53 |
+
storage cannot be obtained.
|
| 54 |
+
|
| 55 |
*Remarks:* The storage for the array is obtained by calling
|
| 56 |
`::operator new` [[new.delete]], but it is unspecified when or how often
|
| 57 |
this function is called. This function starts the lifetime of the array
|
| 58 |
object, but not that of any of the array elements.
|
| 59 |
|
| 60 |
+
``` cpp
|
| 61 |
+
[[nodiscard]] constexpr allocation_result<T*> allocate_at_least(size_t n);
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
*Mandates:* `T` is not an incomplete type [[term.incomplete.type]].
|
| 65 |
+
|
| 66 |
+
*Returns:* `allocation_result<T*>{ptr, count}`, where `ptr` is a pointer
|
| 67 |
+
to the initial element of an array of `count` `T` and `count` ≥ `n`.
|
| 68 |
+
|
| 69 |
*Throws:* `bad_array_new_length` if
|
| 70 |
+
`numeric_limits<size_t>::max() / sizeof(T)` < `n`, or `bad_alloc` if the
|
| 71 |
storage cannot be obtained.
|
| 72 |
|
| 73 |
+
*Remarks:* The storage for the array is obtained by calling
|
| 74 |
+
`::operator new`, but it is unspecified when or how often this function
|
| 75 |
+
is called. This function starts the lifetime of the array object, but
|
| 76 |
+
not that of any of the array elements.
|
| 77 |
+
|
| 78 |
``` cpp
|
| 79 |
constexpr void deallocate(T* p, size_t n);
|
| 80 |
```
|
| 81 |
|
| 82 |
+
*Preconditions:*
|
| 83 |
+
|
| 84 |
+
- If `p` is memory that was obtained by a call to `allocate_at_least`,
|
| 85 |
+
let `ret` be the value returned and `req` be the value passed as the
|
| 86 |
+
first argument to that call. `p` is equal to `ret.ptr` and `n` is a
|
| 87 |
+
value such that `req` ≤ `n` ≤ `ret.count`.
|
| 88 |
+
- Otherwise, `p` is a pointer value obtained from `allocate`. `n` equals
|
| 89 |
+
the value passed as the first argument to the invocation of `allocate`
|
| 90 |
+
which returned `p`.
|
| 91 |
|
| 92 |
*Effects:* Deallocates the storage referenced by `p`.
|
| 93 |
|
| 94 |
*Remarks:* Uses `::operator delete` [[new.delete]], but it is
|
| 95 |
unspecified when this function is called.
|