3#include "../utility/aligned_malloc.h"
4#include "../utility/alignment.h"
5#include "../utility/assert.h"
6#include "../utility/empty_base.h"
7#include "../utility/meta.h"
8#include "../utility/source_location.h"
27 template<
typename Alloc>
52 noexcept(std::is_nothrow_move_constructible_v<node>) :
53 m_Node(std::move(other.m_Node))
55 other.m_Node =
nullptr;
66 noexcept(std::is_nothrow_move_assignable_v<node>)
70 m_Node = std::move(rhs.m_Node);
79 return m_Node == rhs.m_Node;
84 return m_Node != rhs.m_Node;
87#pragma region Allocation
95 std::is_nothrow_default_constructible_v<node> &&
96 detail::has_nothrow_allocate_v<Alloc> &&
97 (!detail::has_max_size_v<Alloc> || detail::has_nothrow_max_size_v<Alloc>))
105 if (n > m_Node->Allocator.max_size())
123 m_Node->Allocations++;
135 std::is_nothrow_destructible_v<node> &&
141 node* prev =
nullptr;
145 if (next->Allocator.owns(p))
147 next->Allocator.deallocate(p, n);
151 if (--next->Allocations == 0 && prev)
153 prev->Next = next->Next;
167#pragma region Construction
175 template<
typename T,
typename... Args>
184 if (next->Allocator.owns(p))
186 next->Allocator.construct(p, std::forward<Args>(args)...);
196 ::new(p) T(std::forward<Args>(args)...);
205 typename std::enable_if<detail::has_destroy_v<Alloc, T*>,
void>::type
213 if (next->Allocator.owns(p))
215 next->Allocator.destroy(p);
229#pragma region Utility
235 template<
typename A = Alloc>
236 typename std::enable_if<detail::has_max_size_v<A>,
size_type>::type
238 noexcept(detail::has_nothrow_max_size_v<A>)
240 return m_Node->Allocator.max_size();
254 if (next->Allocator.owns(p))
266 noexcept(std::is_nothrow_destructible_v<node>)
276 node* current = next;
278 next = current->Next;
#define KTL_ASSERT(x)
Definition assert.h:17
An allocator which owns multiple instances of a given sub allocator. When allocating it will attempt ...
Definition cascading.h:29
void deallocate(void *p, size_type n) noexcept(std::is_nothrow_destructible_v< node > &&detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_deallocate_v< Alloc >)
Attempts to deallocate the memory at location p.
Definition cascading.h:134
std::enable_if< detail::has_max_size_v< A >, size_type >::type max_size() const noexcept(detail::has_nothrow_max_size_v< A >)
Returns the maximum size that an allocation can be.
Definition cascading.h:237
bool operator==(const cascading &rhs) const noexcept
Definition cascading.h:77
cascading & operator=(const cascading &)=delete
cascading(const cascading &)=delete
bool owns(void *p) const noexcept(detail::has_nothrow_owns_v< Alloc >)
Returns whether or not the allocator owns the given location in memory.
Definition cascading.h:248
detail::get_size_type_t< Alloc > size_type
Definition cascading.h:35
std::enable_if< detail::has_construct_v< Alloc, T *, Args... >, void >::type construct(T *p, Args &&... args) noexcept(detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_construct_v< Alloc, T *, Args... >)
Constructs an object of T with the given ...args at the given location.
Definition cascading.h:177
cascading() noexcept
Definition cascading.h:46
void * allocate(size_type n, const source_location source=KTL_SOURCE()) noexcept(std::is_nothrow_default_constructible_v< node > &&detail::has_nothrow_allocate_v< Alloc > &&(!detail::has_max_size_v< Alloc >||detail::has_nothrow_max_size_v< Alloc >))
Attempts to allocate a chunk of memory defined by n.
Definition cascading.h:94
~cascading()
Definition cascading.h:58
bool operator!=(const cascading &rhs) const noexcept
Definition cascading.h:82
cascading(cascading &&other) noexcept(std::is_nothrow_move_constructible_v< node >)
Definition cascading.h:51
std::enable_if< detail::has_destroy_v< Alloc, T * >, void >::type destroy(T *p) noexcept(detail::has_nothrow_owns_v< Alloc > &&detail::has_nothrow_destroy_v< Alloc, T * >)
Destructs an object of T at the given location.
Definition cascading.h:206
cascading & operator=(cascading &&rhs) noexcept(std::is_nothrow_move_assignable_v< node >)
Definition cascading.h:65
#define KTL_EMPTY_BASE
Definition empty_base.h:6
typename get_size_type< Alloc, void >::type get_size_type_t
Definition meta.h:33
constexpr bool has_nothrow_construct_v
Definition meta.h:123
constexpr bool has_construct_v
Definition meta.h:53
void * allocate(Alloc &alloc, size_t n, const source_location source) noexcept(false)
Definition meta.h:161
void aligned_delete(T *p) noexcept(noexcept(p->~T()))
Definition aligned_malloc.h:99
constexpr bool has_no_value_type_v
Definition meta.h:17
constexpr size_t ALIGNMENT
Definition alignment.h:7
Definition cascading.h:16
#define KTL_SOURCE()
Definition source_location.h:11
Definition source_location.h:19