4#ifndef WPI_MEMORY_MEMORY_RESOURCE_ADAPTER_HPP_INCLUDED
5#define WPI_MEMORY_MEMORY_RESOURCE_ADAPTER_HPP_INCLUDED
15#if defined(__has_include) && __has_include(<memory_resource>)
17#if !defined(__GNUC__) || __cplusplus >= 201703L
20#include <memory_resource>
23#elif defined(__has_include) && __has_include(<experimental/memory_resource>)
25#if !defined(__GNUC__) || __cplusplus >= 201402L
28#include <experimental/memory_resource>
33#if defined(__cpp_lib_memory_resource)
38#elif defined(__cpp_lib_experimental_memory_resources)
51 static const std::size_t max_alignment =
alignof(std::max_align_t);
55 void*
allocate(std::size_t
bytes, std::size_t alignment = max_alignment)
59 void deallocate(
void* p, std::size_t
bytes, std::size_t alignment = max_alignment)
75 return &a == &b || a.is_equal(b);
95 template <
class RawAllocator>
98 WPI_EBO(allocator_traits<RawAllocator>::allocator_type)
134 auto div =
bytes / max;
136 auto n = div + (
mod != 0);
150 auto div =
bytes / max;
152 auto n = div + (
mod != 0);
161 return this == &other;
182 return ptr_->allocate(size, alignment);
188 ptr_->deallocate(
ptr, size, alignment);
194 return std::size_t(-1);
210 inline bool operator==(
const memory_resource_allocator& lhs,
211 const memory_resource_allocator& rhs)
noexcept
213 return lhs.resource() == rhs.resource();
219 return !(lhs == rhs);
224 template <
class RawAllocator>
225 struct is_shared_allocator;
The default specialization of the wpi::memory::allocator_traits.
The default specialization of the allocator_traits for a RawAllocator.
Definition allocator_traits.hpp:292
static void deallocate_array(allocator_type &state, void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:328
traits_detail::allocator_type< Allocator > allocator_type
Definition allocator_traits.hpp:294
static void * allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:308
static std::size_t max_node_size(const allocator_type &state)
Definition allocator_traits.hpp:338
static void * allocate_node(allocator_type &state, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:298
static void deallocate_node(allocator_type &state, void *node, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:318
Wraps a RawAllocator and makes it a memory_resource.
Definition memory_resource_adapter.hpp:99
allocator_type & get_allocator() noexcept
Definition memory_resource_adapter.hpp:111
void do_deallocate(void *p, std::size_t bytes, std::size_t alignment) override
Definition memory_resource_adapter.hpp:143
const allocator_type & get_allocator() const noexcept
Definition memory_resource_adapter.hpp:116
bool do_is_equal(const memory_resource &other) const noexcept override
Definition memory_resource_adapter.hpp:159
memory_resource_adapter(allocator_type &&other) noexcept
Definition memory_resource_adapter.hpp:104
typename allocator_traits< RawAllocator >::allocator_type allocator_type
Definition memory_resource_adapter.hpp:101
void * do_allocate(std::size_t bytes, std::size_t alignment) override
Definition memory_resource_adapter.hpp:129
Wraps a memory_resource and makes it a RawAllocator.
Definition memory_resource_adapter.hpp:168
memory_resource * resource() const noexcept
Definition memory_resource_adapter.hpp:198
memory_resource_allocator(memory_resource *ptr) noexcept
Definition memory_resource_adapter.hpp:172
std::size_t max_alignment() const noexcept
Definition memory_resource_adapter.hpp:192
void deallocate_node(void *ptr, std::size_t size, std::size_t alignment) noexcept
Definition memory_resource_adapter.hpp:186
void * allocate_node(std::size_t size, std::size_t alignment)
Definition memory_resource_adapter.hpp:180
The memory_resource abstract base class used in the implementation.
Definition memory_resource_adapter.hpp:91
Definition memory_resource_adapter.hpp:50
void deallocate(void *p, std::size_t bytes, std::size_t alignment=max_alignment)
Definition memory_resource_adapter.hpp:59
virtual void * do_allocate(std::size_t bytes, std::size_t alignment)=0
void * allocate(std::size_t bytes, std::size_t alignment=max_alignment)
Definition memory_resource_adapter.hpp:55
bool is_equal(const memory_resource &other) const noexcept
Definition memory_resource_adapter.hpp:63
virtual ~memory_resource() noexcept
Definition memory_resource_adapter.hpp:54
virtual bool do_is_equal(const memory_resource &other) const noexcept=0
virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment)=0
#define WPI_ALIAS_TEMPLATE(Name,...)
Definition config.hpp:73
std::remove_reference< T >::type && move(T &&arg) noexcept
Definition utility.hpp:25
Memory namespace.
Definition heap_allocator.hpp:20
bool operator!=(const memory_resource_allocator &lhs, const memory_resource_allocator &rhs) noexcept
Definition memory_resource_adapter.hpp:216
bool operator==(std::nullptr_t, const joint_ptr< T, RawAllocator > &ptr)
Definition joint_allocator.hpp:393
Definition memory_resource_adapter.hpp:47
bool operator!=(const memory_resource &a, const memory_resource &b) noexcept
Definition memory_resource_adapter.hpp:77
bool operator==(const memory_resource &a, const memory_resource &b) noexcept
Definition memory_resource_adapter.hpp:73
Foonathan namespace.
Definition ntcore_cpp.h:26
constexpr T mod(U Numerator, V Denominator)
Returns the remainder of the Euclidean division of LHS by RHS.
Definition MathExtras.h:432
Specifies whether or not a RawAllocator has shared semantics.
Definition allocator_storage.hpp:534
#define WPI_MEMORY_ASSERT(Expr)
Definition assert.hpp:46