|
BDE 4.14.0 Production release
|
Provide a minimal standard compliant allocator.
This component provides an allocator, bsltf::StdStatefulAllocator, that defines the minimal interface to comply with section 17.6.3.5 ([allocator.requirements]) of the C++11 standard, while still providing an externally visible and potentially distinct state for each allocator object. This type can be used to verify that constructs designed to support a standard-compliant allocator access the allocator only through the standard-defined interface.
StdStatefulAllocator delegates its operations to the allocator passed at construction (or the default allocator if no allocator is passed) that is also the sole attribute of this class. In most tests, a bslma::TestAllocator will be passed.
The key differences between this test allocator and a regular BDE allocator are:
scoped allocation model, so that elements in a container will often have a different allocator to the container object itself.swap operations, depending on how the template is configured as it is instantiated.This section illustrates intended use of this component.
In this example we will verify that a type supports the use of a STL-compliant allocator.
First, we define a simple container type intended to be used with a C++11 standard compliant allocator:
Then, we define the member functions of MyContainer:
Now, we use bsltf::StdStatefulAllocator to implement a simple test for MyContainer to verify it correctly uses a parameterized allocator using only the C++11 standard methods: