Template Class single_allocator

Class Documentation

template<class U>
class apex::_vector_impl::single_allocator

An allocator which can only be used to allocate memory once.

Template Parameters

U – The type to allocate.

Public Types

using base_type = std::allocator<U>
using value_type = U
using propagate_on_container_copy_assignment = std::true_type
using propagate_on_container_move_assignment = std::true_type
using propagate_on_container_swap = std::true_type

Public Functions

inline explicit single_allocator(const typename base_type::size_type n)

Constructor

Parameters

n – The maximum number of allocatable elements.

inline single_allocator(const single_allocator<U> &other)

Copy constructor.

inline single_allocator<U> &operator=(const _vector_impl::single_allocator<U> &other)

Copy assignment operator.

inline single_allocator(single_allocator<U> &&other) noexcept

Move constructor.

inline single_allocator<U> &operator=(single_allocator<U> &&other) noexcept

Move assignment.

inline base_type::pointer allocate(const typename base_type::size_type n, const void *hint = 0)

Allocates memory. This special allocator imposes the following constraints:

  • Memory can only allocated once, subsequent attempts throw std::bad_alloc.

  • The number allocated must match the size specified when constructed the allocator.

Parameters
  • n – The number of elements to allocate memory for.

  • hint – Pointer to nearby memory location.

Throws

std::bad_alloc – if there there is no memory available.

Returns

Pointer to the first byte of a memory block suitably aligned and sufficient to hold an array of n objects of type T.

inline void deallocate(typename base_type::pointer ptr, typename base_type::size_type n)

Deallocates memory.

Parameters
  • ptr – Pointer to the memory to deallocate.

  • n – Number of elements to deallocate.

inline base_type::size_type max_size() const

The maximum number of elements allocatable.