4 #ifndef LEXY_DETAIL_MEMORY_RESOURCE_HPP_INCLUDED
5 #define LEXY_DETAIL_MEMORY_RESOURCE_HPP_INCLUDED
17 void* allocate(std::size_t
bytes, std::size_t alignment);
18 void deallocate(
void* ptr, std::size_t
bytes, std::size_t alignment);
20 friend bool operator==(
const MemoryResource& lhs,
const MemoryResource& rhs);
31 if (alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
32 return ::operator
new(
bytes, std::align_val_t{alignment});
34 return ::operator
new(
bytes);
37 static void deallocate(
void* ptr, std::size_t
bytes, std::size_t alignment) noexcept
39 #if LEXY_ENABLE_ASSERT
45 std::memset(ptr, 0xFF,
bytes);
48 #ifdef __cpp_sized_deallocation
49 if (alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
50 ::operator
delete(ptr,
bytes, std::align_val_t{alignment});
52 ::operator
delete(ptr,
bytes);
56 if (alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
57 ::operator
delete(ptr, std::align_val_t{alignment});
59 ::operator
delete(ptr);
72 template <
typename MemoryResource>
81 return MemoryResource{};
88 MemoryResource _resource;
90 constexpr MemoryResource*
operator->() noexcept
99 constexpr MemoryResource*
get() const noexcept
105 template <
typename MemoryResource>
124 constexpr MemoryResource*
get() const noexcept
134 template <
typename MemoryResource>
136 = std::conditional_t<std::is_void_v<MemoryResource>,
138 std::conditional_t<std::is_empty_v<MemoryResource>,
143 template <
typename MemoryResource,
typename = std::enable_if_t<std::is_
void_v<MemoryResource>
144 || std::is_empty_v<MemoryResource>>>
151 #endif // LEXY_DETAIL_MEMORY_RESOURCE_HPP_INCLUDED