memory
Typedefs | Member Functions | Related Functions
any_std_allocator< T > Class Template Reference

Detailed Description

template<typename T>
class foonathan::memory::any_std_allocator< T >

An alias template for std_allocator using a type-erased RawAllocator.

This is the same as using a std_allocator with the tag type any_allocator. The implementation is optimized to call fewer virtual functions.

Typedefs

using value_type = T
 
using pointer = T *
 
using const_pointer = const T *
 
using reference = T &
 
using const_reference = const T &
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using propagate_on_container_swap = typename prop_traits::propagate_on_container_swap
 
using propagate_on_container_move_assignment = typename prop_traits::propagate_on_container_move_assignment
 
using propagate_on_container_copy_assignment = typename prop_traits::propagate_on_container_copy_assignment
 
using allocator_type = typename alloc_reference::allocator_type
 

Member Functions

std_allocator< T, any_allocatorselect_on_container_copy_construction () const
 
pointer allocate (size_type n, void *=nullptr)
 
void deallocate (pointer p, size_type n) noexcept
 
void construct (U *p, Args &&... args)
 
void destroy (U *p) noexcept
 
size_type max_size () const noexcept
 
auto get_allocator () noexcept -> decltype(std::declval< alloc_reference >().get_allocator())
 
auto get_allocator () const noexcept -> decltype(std::declval< const alloc_reference >().get_allocator())
 

Related Functions

template<typename T , class RawAllocator >
any_std_allocator< T > make_any_std_allocator (RawAllocator &&allocator) noexcept
 
bool operator== (const std_allocator< T, Impl > &lhs, const std_allocator< U, Impl > &rhs) noexcept
 
bool operator!= (const std_allocator< T, Impl > &lhs, const std_allocator< U, Impl > &rhs) noexcept
 
auto make_std_allocator (any_allocator &&allocator) noexcept -> std_allocator< T, typename std::decay< any_allocator >::type >
 

Member Functions

◆ select_on_container_copy_construction()

std_allocator< T, any_allocator > select_on_container_copy_construction ( ) const
inherited
Returns:
A copy of the allocator. This is required by the Allocator concept and forwards to the propagation_traits.

◆ allocate()

pointer allocate ( size_type  n,
void *  = nullptr 
)
inherited
Effects:
Allocates memory using the underlying RawAllocator. If n is 1, it will call allocate_node(sizeof(T), alignof(T)), otherwise allocate_array(n, sizeof(T), alignof(T)).
Returns:
A pointer to a memory block suitable for n objects of type T.
Throws:
Anything thrown by the RawAllocator.

◆ deallocate()

void deallocate ( pointer  p,
size_type  n 
)
noexceptinherited
Effects:
Deallcoates memory using the underlying RawAllocator. It will forward to the deallocation function in the same way as in allocate().
Requires:
The pointer must come from a previous call to allocate() with the same n on this object or any copy of it.

◆ construct()

void construct ( U *  p,
Args &&...  args 
)
inherited
Effects:
Creates an object of type U at given address using the passed arguments.

◆ destroy()

void destroy ( U *  p)
noexceptinherited
Effects:
Calls the destructor for an object of type U at given address.

◆ max_size()

size_type max_size ( ) const
noexceptinherited
Returns:
The maximum size for an allocation which is max_array_size() / sizeof(value_type). This is only an upper bound, not the exact maximum.

◆ get_allocator() [1/2]

auto get_allocator ( ) -> decltype(std::declval<alloc_reference>().get_allocator())
noexceptinherited
Effects:
Returns a reference to the referenced allocator.
Returns:
For stateful allocators: A (const) reference to the stored allocator. For stateless allocators: A temporary constructed allocator.

◆ get_allocator() [2/2]

auto get_allocator ( ) const -> decltype(std::declval<const alloc_reference>().get_allocator())
noexceptinherited
Effects:
Returns a reference to the referenced allocator.
Returns:
For stateful allocators: A (const) reference to the stored allocator. For stateless allocators: A temporary constructed allocator.

Related Functions

◆ make_any_std_allocator()

any_std_allocator< T > make_any_std_allocator ( RawAllocator &&  allocator)
related
Returns:
A new any_std_allocator for a given type using a certain allocator object.

◆ operator==()

bool operator== ( const std_allocator< T, Impl > &  lhs,
const std_allocator< U, Impl > &  rhs 
)
related
Effects:
Compares two std_allocator object, they are equal if either stateless or reference the same allocator.
Returns:
The result of the comparision for equality.

◆ operator!=()

bool operator!= ( const std_allocator< T, Impl > &  lhs,
const std_allocator< U, Impl > &  rhs 
)
related
Effects:
Compares two std_allocator object, they are equal if either stateless or reference the same allocator.
Returns:
The result of the comparision for inequality.

◆ make_std_allocator()

auto make_std_allocator ( any_allocator &&  allocator) -> std_allocator<T, typename std::decay<any_allocator >::type>
related
Returns:
A new std_allocator for a given type using a certain allocator object.