KTL
ktl::type_allocator< T, Alloc > Class Template Reference

Wrapper class for making an untyped allocator into a typed allocator. More...

#include <type_allocator.h>

Classes

struct  rebind
 

Public Types

typedef T value_type
 
typedef detail::get_size_type_t< Alloc > size_type
 
typedef std::false_type is_always_equal
 

Public Member Functions

 type_allocator ()=default
 Default constructor. More...
 
template<typename... Args, typename = std::enable_if_t< std::is_constructible_v<Alloc, Args...>>>
 type_allocator (Args &&... alloc) noexcept(std::is_nothrow_constructible_v< T, Args... >)
 Constructor for forwarding any arguments to the underlying allocator. More...
 
 type_allocator (const type_allocator &)=default
 
 type_allocator (type_allocator &&other) noexcept(std::is_nothrow_copy_constructible_v< Alloc >)
 
template<typename U >
 type_allocator (const type_allocator< U, Alloc > &other) noexcept(std::is_nothrow_constructible_v< Alloc, const type_allocator< U, Alloc > & >)
 
template<typename U >
 type_allocator (type_allocator< U, Alloc > &&other) noexcept(std::is_nothrow_constructible_v< Alloc, type_allocator< U, Alloc > && >)
 
type_allocatoroperator= (const type_allocator &)=default
 
type_allocatoroperator= (type_allocator &&rhs) noexcept(std::is_nothrow_copy_assignable_v< Alloc >)
 
value_typeallocate (size_t n) noexcept(noexcept(m_Alloc.allocate(n)))
 Attempts to allocate a chunk of memory defined by n. More...
 
void deallocate (value_type *p, size_t n) noexcept(noexcept(m_Alloc.deallocate(p, n)))
 Attempts to deallocate the memory at location p. More...
 
template<typename... Args>
std::enable_if< detail::has_construct_v< Alloc, value_type *, Args... >, void >::type construct (value_type *p, Args &&... args) noexcept(detail::has_nothrow_construct_v< Alloc, value_type *, Args... >)
 Constructs an object of T with the given ...args at the given location. More...
 
template<typename A = Alloc>
std::enable_if< detail::has_destroy_v< A, value_type * >, void >::type destroy (value_type *p) noexcept(detail::has_nothrow_destroy_v< Alloc, value_type * >)
 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 of objects can be. More...
 
template<typename A = Alloc>
std::enable_if< detail::has_owns_v< A >, bool >::type owns (value_type *p) const noexcept(detail::has_nothrow_owns_v< A >)
 Returns whether or not the allocator owns the given location in memory. More...
 
Alloc & get_allocator () noexcept
 Returns a reference to the underlying allocator. More...
 
const Alloc & get_allocator () const noexcept
 Returns a const reference to the underlying allocator. More...
 

Friends

template<typename U , typename A >
class type_allocator
 

Detailed Description

template<typename T, typename Alloc>
class ktl::type_allocator< T, Alloc >

Wrapper class for making an untyped allocator into a typed allocator.

Template Parameters
TThe type to use
AllocThe untyped allocator

Member Typedef Documentation

◆ is_always_equal

template<typename T , typename Alloc >
typedef std::false_type ktl::type_allocator< T, Alloc >::is_always_equal

◆ size_type

template<typename T , typename Alloc >
typedef detail::get_size_type_t<Alloc> ktl::type_allocator< T, Alloc >::size_type

◆ value_type

template<typename T , typename Alloc >
typedef T ktl::type_allocator< T, Alloc >::value_type

Constructor & Destructor Documentation

◆ type_allocator() [1/6]

template<typename T , typename Alloc >
ktl::type_allocator< T, Alloc >::type_allocator ( )
default

Default constructor.

Note
Only defined if the underlying allocator defines it

◆ type_allocator() [2/6]

template<typename T , typename Alloc >
template<typename... Args, typename = std::enable_if_t< std::is_constructible_v<Alloc, Args...>>>
ktl::type_allocator< T, Alloc >::type_allocator ( Args &&...  alloc)
inlineexplicitnoexcept

Constructor for forwarding any arguments to the underlying allocator.

◆ type_allocator() [3/6]

template<typename T , typename Alloc >
ktl::type_allocator< T, Alloc >::type_allocator ( const type_allocator< T, Alloc > &  )
default

◆ type_allocator() [4/6]

template<typename T , typename Alloc >
ktl::type_allocator< T, Alloc >::type_allocator ( type_allocator< T, Alloc > &&  other)
inlinenoexcept

◆ type_allocator() [5/6]

template<typename T , typename Alloc >
template<typename U >
ktl::type_allocator< T, Alloc >::type_allocator ( const type_allocator< U, Alloc > &  other)
inlinenoexcept

◆ type_allocator() [6/6]

template<typename T , typename Alloc >
template<typename U >
ktl::type_allocator< T, Alloc >::type_allocator ( type_allocator< U, Alloc > &&  other)
inlinenoexcept

Member Function Documentation

◆ allocate()

template<typename T , typename Alloc >
value_type* ktl::type_allocator< T, Alloc >::allocate ( size_t  n)
inlinenoexcept

Attempts to allocate a chunk of memory defined by n.

Parameters
nThe amount of objects to allocate memory for. Not in bytes, but number of T
Returns
A location in memory that is at least n objects big or nullptr if it could not be allocated

◆ construct()

template<typename T , typename Alloc >
template<typename... Args>
std::enable_if<detail::has_construct_v<Alloc, value_type*, Args...>, void>::type ktl::type_allocator< T, Alloc >::construct ( value_type 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 T , typename Alloc >
void ktl::type_allocator< T, Alloc >::deallocate ( value_type p,
size_t  n 
)
inlinenoexcept

Attempts to deallocate the memory at location p.

Parameters
pThe location in memory to deallocate
nThe size that was initially allocated

◆ destroy()

template<typename T , typename Alloc >
template<typename A = Alloc>
std::enable_if<detail::has_destroy_v<A, value_type*>, void>::type ktl::type_allocator< T, Alloc >::destroy ( value_type 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

◆ get_allocator() [1/2]

template<typename T , typename Alloc >
const Alloc& ktl::type_allocator< T, Alloc >::get_allocator ( ) const
inlinenoexcept

Returns a const reference to the underlying allocator.

Returns
The allocator

◆ get_allocator() [2/2]

template<typename T , typename Alloc >
Alloc& ktl::type_allocator< T, Alloc >::get_allocator ( )
inlinenoexcept

Returns a reference to the underlying allocator.

Returns
The allocator

◆ max_size()

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

Returns the maximum size that an allocation of objects can be.

Note
Only defined if the underlying allocator defines it
Returns
The maximum size an allocation may be. Not in bytes, but number of T

◆ operator=() [1/2]

template<typename T , typename Alloc >
type_allocator& ktl::type_allocator< T, Alloc >::operator= ( const type_allocator< T, Alloc > &  )
default

◆ operator=() [2/2]

template<typename T , typename Alloc >
type_allocator& ktl::type_allocator< T, Alloc >::operator= ( type_allocator< T, Alloc > &&  rhs)
inlinenoexcept

◆ owns()

template<typename T , typename Alloc >
template<typename A = Alloc>
std::enable_if<detail::has_owns_v<A>, bool>::type ktl::type_allocator< T, Alloc >::owns ( value_type p) const
inlinenoexcept

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

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

Friends And Related Function Documentation

◆ type_allocator

template<typename T , typename Alloc >
template<typename U , typename A >
friend class type_allocator
friend

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