Documentation of memory

( foonathan/memory)

any_std_allocator< T, Mutex > Class Template Reference

Detailed Description

template<typename T, class Mutex = default_mutex>
class foonathan::memory::any_std_allocator< T, Mutex >

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
 
using mutex = Mutex
 

Member Functions

std_allocator< T, any_allocator, Mutex > select_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())
 
auto lock () noexcept -> decltype(std::declval< alloc_reference >().lock())
 
auto lock () const noexcept -> decltype(std::declval< const alloc_reference >().lock())
 

Related Functions

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

Member Functions

§ select_on_container_copy_construction()

std_allocator<T, any_allocator , Mutex> 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.
Note
This does not lock the Mutex.

§ 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.
Note
This does not lock the Mutex.

§ lock() [1/2]

auto lock ( ) -> decltype(std::declval<alloc_reference>().lock())
noexceptinherited
Returns:
A proxy object that acts like a pointer to the stored allocator. It cannot be reassigned to point to another allocator object and only moving is supported, which is destructive. As long as the proxy object lives and is not moved from, the Mutex will be kept locked.
Requires:
The result of get_allocator() must not be a temporary, otherwise the body of this function will not compile.

§ lock() [2/2]

auto lock ( ) const-> decltype(std::declval<const alloc_reference>().lock())
noexceptinherited
Returns:
A proxy object that acts like a pointer to the stored allocator. It cannot be reassigned to point to another allocator object and only moving is supported, which is destructive. As long as the proxy object lives and is not moved from, the Mutex will be kept locked.
Requires:
The result of get_allocator() must not be a temporary, otherwise the body of this function will not compile.

Related Functions

§ make_any_std_allocator() [1/2]

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.

§ make_any_std_allocator() [2/2]

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

§ operator==()

bool operator== ( const std_allocator< T, Impl, Mut > &  lhs,
const std_allocator< U, Impl, Mut > &  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, Mut > &  lhs,
const std_allocator< U, Impl, Mut > &  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() [1/2]

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.

§ make_std_allocator() [2/2]

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