tmp/tmppkgmbvin/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="mem.poly.allocator.class.general">[[mem.poly.allocator.class.general]]</a>
|
| 2 |
+
|
| 3 |
+
A specialization of class template `pmr::polymorphic_allocator` meets
|
| 4 |
+
the *Cpp17Allocator* requirements [[allocator.requirements.general]] if
|
| 5 |
+
its template argument is a cv-unqualified object type. Constructed with
|
| 6 |
+
different memory resources, different instances of the same
|
| 7 |
+
specialization of `pmr::polymorphic_allocator` can exhibit entirely
|
| 8 |
+
different allocation behavior. This runtime polymorphism allows objects
|
| 9 |
+
that use `polymorphic_allocator` to behave as if they used different
|
| 10 |
+
allocator types at run time even though they use the same static
|
| 11 |
+
allocator type.
|
| 12 |
+
|
| 13 |
+
A specialization of class template `pmr::polymorphic_allocator` meets
|
| 14 |
+
the allocator completeness requirements
|
| 15 |
+
[[allocator.requirements.completeness]] if its template argument is a
|
| 16 |
+
cv-unqualified object type.
|
| 17 |
+
|
| 18 |
+
``` cpp
|
| 19 |
+
namespace std::pmr {
|
| 20 |
+
template<class Tp = byte> class polymorphic_allocator {
|
| 21 |
+
memory_resource* memory_rsrc; // exposition only
|
| 22 |
+
|
| 23 |
+
public:
|
| 24 |
+
using value_type = Tp;
|
| 25 |
+
|
| 26 |
+
// [mem.poly.allocator.ctor], constructors
|
| 27 |
+
polymorphic_allocator() noexcept;
|
| 28 |
+
polymorphic_allocator(memory_resource* r);
|
| 29 |
+
|
| 30 |
+
polymorphic_allocator(const polymorphic_allocator& other) = default;
|
| 31 |
+
|
| 32 |
+
template<class U>
|
| 33 |
+
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
|
| 34 |
+
|
| 35 |
+
polymorphic_allocator& operator=(const polymorphic_allocator&) = delete;
|
| 36 |
+
|
| 37 |
+
// [mem.poly.allocator.mem], member functions
|
| 38 |
+
[[nodiscard]] Tp* allocate(size_t n);
|
| 39 |
+
void deallocate(Tp* p, size_t n);
|
| 40 |
+
|
| 41 |
+
[[nodiscard]] void* allocate_bytes(size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 42 |
+
void deallocate_bytes(void* p, size_t nbytes, size_t alignment = alignof(max_align_t));
|
| 43 |
+
template<class T> [[nodiscard]] T* allocate_object(size_t n = 1);
|
| 44 |
+
template<class T> void deallocate_object(T* p, size_t n = 1);
|
| 45 |
+
template<class T, class... CtorArgs> [[nodiscard]] T* new_object(CtorArgs&&... ctor_args);
|
| 46 |
+
template<class T> void delete_object(T* p);
|
| 47 |
+
|
| 48 |
+
template<class T, class... Args>
|
| 49 |
+
void construct(T* p, Args&&... args);
|
| 50 |
+
|
| 51 |
+
polymorphic_allocator select_on_container_copy_construction() const;
|
| 52 |
+
|
| 53 |
+
memory_resource* resource() const;
|
| 54 |
+
|
| 55 |
+
// friends
|
| 56 |
+
friend bool operator==(const polymorphic_allocator& a,
|
| 57 |
+
const polymorphic_allocator& b) noexcept {
|
| 58 |
+
return *a.resource() == *b.resource();
|
| 59 |
+
}
|
| 60 |
+
};
|
| 61 |
+
}
|
| 62 |
+
```
|
| 63 |
+
|