1 #ifndef ZSERIO_PMR_POLYMORPHIC_ALLOCATOR_H_INC
2 #define ZSERIO_PMR_POLYMORPHIC_ALLOCATOR_H_INC
21 template <
class T = u
int8_t>
22 class PolymorphicAllocatorBase
29 using pointer = value_type*;
30 using const_pointer =
const value_type*;
31 using size_type = size_t;
32 using difference_type = ptrdiff_t;
33 using reference = value_type&;
34 using const_reference =
const value_type&;
54 ~PolymorphicAllocatorBase() =
default;
56 PolymorphicAllocatorBase(
const PolymorphicAllocatorBase& other) noexcept =
default;
57 PolymorphicAllocatorBase& operator=(
const PolymorphicAllocatorBase& other) noexcept =
default;
59 PolymorphicAllocatorBase(PolymorphicAllocatorBase&& other) noexcept =
default;
60 PolymorphicAllocatorBase& operator=(PolymorphicAllocatorBase&& other) noexcept =
default;
71 PolymorphicAllocatorBase(
const PolymorphicAllocatorBase<U>& other) noexcept :
72 m_resource(other.resource())
81 PolymorphicAllocatorBase& operator=(
const PolymorphicAllocatorBase<U>& other) noexcept
83 m_resource = other.resource();
92 value_type* allocate(
size_t size)
94 return static_cast<value_type*
>(m_resource->allocate(size *
sizeof(value_type),
alignof(value_type)));
104 void deallocate(value_type* memory,
size_t size) noexcept
106 m_resource->deallocate(memory, size *
sizeof(value_type),
alignof(value_type));
112 MemoryResource* resource() const noexcept
125 template <
typename U,
typename... Args>
126 void construct(U* ptr, Args&&... args) noexcept(
127 noexcept(
new (
static_cast<void*
>(ptr)) U(std::forward<Args>(args)...)))
129 new (
static_cast<void*
>(ptr)) U(std::forward<Args>(args)...);
139 template <
typename U>
140 void destroy(U* ptr) noexcept(noexcept(ptr->~U()))
152 size_type max_size() const noexcept
154 return std::numeric_limits<size_type>::max() /
sizeof(value_type);
158 MemoryResource* m_resource;
161 template <
class T,
class U>
162 bool operator==(
const PolymorphicAllocatorBase<T>& lhs,
const PolymorphicAllocatorBase<U>& rhs) noexcept
164 return *lhs.resource() == *rhs.resource();
167 template <
class T,
class U>
168 bool operator!=(
const PolymorphicAllocatorBase<T>& lhs,
const PolymorphicAllocatorBase<U>& rhs) noexcept
170 return !(lhs == rhs);
179 template <
class T = u
int8_t>
183 using detail::PolymorphicAllocatorBase<T>::PolymorphicAllocatorBase;
202 template <
typename U>
212 template <
class T = u
int8_t>
216 using detail::PolymorphicAllocatorBase<T>::PolymorphicAllocatorBase;
235 template <
typename U>
std::false_type propagate_on_container_copy_assignment
PolymorphicAllocator select_on_container_copy_construction() const
std::false_type propagate_on_container_move_assignment
std::false_type propagate_on_container_swap
PropagatingPolymorphicAllocator select_on_container_copy_construction() const
std::true_type propagate_on_container_move_assignment
std::true_type propagate_on_container_copy_assignment
std::true_type propagate_on_container_swap
bool operator==(const MemoryResource &lhs, const MemoryResource &rhs)
MemoryResource * getDefaultResource() noexcept
bool operator!=(const MemoryResource &lhs, const MemoryResource &rhs)