BloombergLP::bslma::StdTestAllocator

An STL-compatible test allocator that forwards allocation calls to an underlying mechanism object of a type derived from bslma::TestAllocator. This class template adheres to the allocator requirements defined in section 20.1.5 [lib.allocator.requirements]of the C++ standard and may be used to instantiate any [container]class template that follows the STL allocator protocol. The allocation mechanism is chosen at run-time, giving the programmer run-time control over how a container allocates and frees memory.

Synopsis

Declared in <bslma_stdtestallocator.h>

template<class TYPE>
class StdTestAllocator;

Types

NameDescription
rebind This nested struct template, parameterized by ANY_TYPE, provides a namespace for an other type alias, which is a StdTestAllocator type following the same template as this one but that allocates elements of ANY_TYPE. Note that this StdTestAllocator type is convertible to and from other for any type, including void.

Type Aliases

NameDescription
const_pointer Alias for a pointer to constant value type.
const_reference Alias for a constant reference to the value type.
difference_type Alias for the allocator difference type.
pointer Alias for a pointer to the value type.
reference Alias for a modifiable reference to the value type.
size_type Alias for the allocator size type.
value_type Alias for the value type.

Member Functions

NameDescription
StdTestAllocator [constructor]Constructors
address Return the address of the object referred to by the specified x, even if the (template parameter) TYPE overloads the unary operator&.
allocate Allocate enough (properly aligned) space for the specified n objects of (template parameter) TYPE by calling allocate on the mechanism object. The optionally specified hint argument is ignored by this test allocator type. The behavior is undefined unless n <= max_size().
construct Copy-construct an object of (template parameter) TYPE from the specified val at the memory address specified by address. Do not directly allocate memory. The behavior is undefined unless address is not properly aligned for objects of the given TYPE.
deallocate Return memory previously allocated with allocate to the underlying mechanism object by calling deallocate on the mechanism object with the specified p. The optionally specified n argument is ignored by this test allocator type.
destroy Call the TYPE destructor for the object pointed to by the specified p. Do not directly deallocate any memory.
max_size Return the maximum number of elements of (template parameter) TYPE that can be allocated using this test allocator. Note that there is no guarantee that attempts at allocating fewer elements than the value returned by max_size will not throw.
mechanism Return a pointer to the mechanism object to which this proxy forwards allocation and deallocation calls.
operator BloombergLP::bslmf::NestedTraitDeclaration<StdTestAllocator, IsBitwiseCopyable> Declare StdTestAllocator as bitwise copyable.
operator BloombergLP::bslmf::NestedTraitDeclaration<StdTestAllocator, IsBitwiseEqualityComparable> Declare StdTestAllocator as bitwise equality comparable.
operator BloombergLP::bslmf::NestedTraitDeclaration<StdTestAllocator, IsBitwiseMoveable> Declare StdTestAllocator as bitwise moveable.
operator BloombergLP::bslmf::NestedTraitDeclaration<StdTestAllocator, IsStdAllocator> Declare StdTestAllocator as an STL-compatible allocator.

Non-Member Functions

NameDescription
operator!=Return true unless the specified lhs and rhs are proxies for the same bslma::TestAllocator object, in which case return false. This is a practical implementation of the STL requirement that two allocators compare equal if and only if memory allocated from one can be deallocated from the other. Note that the two allocators need not be instantiated on the same type in order to compare equal.
operator!=Return true unless the specified lhs is a proxy for the specified rhs, in which case return false.
operator==Return true if the specified lhs and rhs are proxies for the same bslma::TestAllocator object.
operator==Return true if the specified lhs is a proxy for the specified rhs, and false otherwise.