14 #include <type_traits> 28 template <
typename Resource,
typename T,
typename DefaultResource =
void>
43 template <
typename D =
void,
typename = std::enable_if_t<std::is_invocable_r_v<Resource*, DefaultResource>, D>>
54 return reinterpret_cast<T*>(
m_resource->template
allocate<
alignof( T )>(
n *
sizeof( T ) ) );
60 m_resource->deallocate( reinterpret_cast<std::byte*>( p ),
n *
sizeof( T ) );
79 template <
typename,
typename,
typename>
85 template <
typename Resource,
typename T,
typename U,
typename DefaultResource>
88 return !( lhs == rhs );
Resource * resource() const noexcept
Return a pointer to the memory resource.
Arena()
Construct an allocator using the resource provided by DefaultResource.
Custom allocator holding a pointer to a generic memory resource.
constexpr Arena(Resource *resource) noexcept
Construct an allocator using the given memory resource, which must be valid.
T * allocate(std::size_t n)
Allocate storage for n objects.
void deallocate(T *p, std::size_t n) noexcept
Deallocate storage for n objects.
constexpr bool operator!=(Arena< Resource, T, DefaultResource > const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
friend constexpr bool operator==(Arena const &lhs, Arena< Resource, U, DefaultResource > const &rhs)
constexpr Arena(Arena< Resource, U, DefaultResource > const &other) noexcept
Converting copy constructor, rebinding U -> T.