KTL
ktl::cascading< Alloc > Class Template Reference

An allocator which owns multiple instances of a given sub allocator. When allocating it will attempt to use the first available allocator. Upon failure it will instead create a new instance and allocate from it. More...

#include <cascading.h>

Public Types

typedef detail::get_size_type_t< Alloc > size_type
 

Public Member Functions

 cascading () noexcept
 
 cascading (const cascading &)=delete
 
 cascading (cascading &&other) noexcept(std::is_nothrow_move_constructible_v< node >)
 
 ~cascading ()
 
cascadingoperator= (const cascading &)=delete
 
cascadingoperator= (cascading &&rhs) noexcept(std::is_nothrow_move_assignable_v< node >)
 
bool operator== (const cascading &rhs) const noexcept
 
bool operator!= (const cascading &rhs) const noexcept
 
void * allocate (size_type n) 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. More...
 
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. More...
 
template<typename T , typename... Args>
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. More...
 
template<typename T >
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. More...
 
template<typename A = Alloc>
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. More...
 
bool owns (void *p) const noexcept(detail::has_nothrow_owns_v< Alloc >)
 Returns whether or not the allocator owns the given location in memory. More...
 

Detailed Description

template<typename Alloc>
class ktl::cascading< Alloc >

An allocator which owns multiple instances of a given sub allocator. When allocating it will attempt to use the first available allocator. Upon failure it will instead create a new instance and allocate from it.

Note
Deallocation can take O(n) time as it may have to traverse multiple allocator instances to find the right one. The allocator type must be default-constructible, which means any variation of stack_allocator can't be used. The allocator type must also have an owns(*ptr) method, which means any variation of mallocator can't be used.
Template Parameters
AllocThe allocator type to create instances from
AtomicThe atomic type to use for reference counting. Threading is not implemented, so this defaults to ktl::notomic<size_t>

Member Typedef Documentation

◆ size_type

template<typename Alloc >
typedef detail::get_size_type_t<Alloc> ktl::cascading< Alloc >::size_type

Constructor & Destructor Documentation

◆ cascading() [1/3]

template<typename Alloc >
ktl::cascading< Alloc >::cascading ( )
inlinenoexcept

◆ cascading() [2/3]

template<typename Alloc >
ktl::cascading< Alloc >::cascading ( const cascading< Alloc > &  )
delete

◆ cascading() [3/3]

template<typename Alloc >
ktl::cascading< Alloc >::cascading ( cascading< Alloc > &&  other)
inlinenoexcept

◆ ~cascading()

template<typename Alloc >
ktl::cascading< Alloc >::~cascading ( )
inline

Member Function Documentation

◆ allocate()

template<typename Alloc >
void* ktl::cascading< Alloc >::allocate ( size_type  n)
inlinenoexcept

Attempts to allocate a chunk of memory defined by n.

Note
May create a new instance of the underlying allocator and attempt to allocate using it
Parameters
nThe amount of bytes to allocate memory for
Returns
A location in memory that is at least n bytes big or nullptr if it could not be allocated

◆ construct()

template<typename Alloc >
template<typename T , typename... Args>
std::enable_if<detail::has_construct_v<Alloc, T*, Args...>, void>::type ktl::cascading< Alloc >::construct ( T *  p,
Args &&...  args 
)
inlinenoexcept

Constructs an object of T with the given ...args at the given location.

Note
Only defined if the underlying allocator defines it
Template Parameters
...ArgsThe types of the arguments
Parameters
pThe location of the object in memory
...argsA range of arguments to use to construct the object

◆ deallocate()

template<typename Alloc >
void ktl::cascading< Alloc >::deallocate ( void *  p,
size_type  n 
)
inlinenoexcept

Attempts to deallocate the memory at location p.

Note
Deallocation can take O(n) time as it may have to traverse all allocator instances
Parameters
pThe location in memory to deallocate
nThe size that was initially allocated

◆ destroy()

template<typename Alloc >
template<typename T >
std::enable_if<detail::has_destroy_v<Alloc, T*>, void>::type ktl::cascading< Alloc >::destroy ( T *  p)
inlinenoexcept

Destructs an object of T at the given location.

Note
Only defined if the underlying allocator defines it
Parameters
pThe location of the object in memory

◆ max_size()

template<typename Alloc >
template<typename A = Alloc>
std::enable_if<detail::has_max_size_v<A>, size_type>::type ktl::cascading< Alloc >::max_size ( ) const
inlinenoexcept

Returns the maximum size that an allocation can be.

Note
Only defined if the underlying allocator defines it
Returns
The maximum size an allocation may be

◆ operator!=()

template<typename Alloc >
bool ktl::cascading< Alloc >::operator!= ( const cascading< Alloc > &  rhs) const
inlinenoexcept

◆ operator=() [1/2]

template<typename Alloc >
cascading& ktl::cascading< Alloc >::operator= ( cascading< Alloc > &&  rhs)
inlinenoexcept

◆ operator=() [2/2]

template<typename Alloc >
cascading& ktl::cascading< Alloc >::operator= ( const cascading< Alloc > &  )
delete

◆ operator==()

template<typename Alloc >
bool ktl::cascading< Alloc >::operator== ( const cascading< Alloc > &  rhs) const
inlinenoexcept

◆ owns()

template<typename Alloc >
bool ktl::cascading< Alloc >::owns ( void *  p) const
inlinenoexcept

Returns whether or not the allocator owns the given location in memory.

Parameters
pThe location of the object in memory
Returns
Whether the allocator owns p

The documentation for this class was generated from the following file: