HP Integrity NonStop H-Series User Manual
Page 204
![background image](/manuals/396950/204/background.png)
Standard C++ Library allocators, otherwise you must use the alternative.
The first place that you use RWSTD_ALLOCATOR is when determining which typenames the
container must use to reflect the interface. To do this, place the equivalent of the following code
in your container class definition:
#ifdef RWSTD_ALLOCATOR
typedef typename Allocator::types
reference;
typedef typename Allocator::types
const_reference;
typedef typename Allocator::types
link_type;
Allocator the_allocator;
#else
typedef typename
allocator_interface
typedef typename
allocator_interface
const_reference;
typedef typename
allocator_interface
Allocator alloc;
allocator_interface
allocator_interface
#endif
Notice that the alternative allocator (allocator_interface) has two parts: value_allocator and
node_allocator. You will need to assemble these inside the constructor for your container, if you
use the alternative allocator. In our example, the mechanism for initializing allocator_interface
objects looks like this:
#ifndef RWSTD_ALLOCATOR
node_allocator.alloc(alloc);
value_allocator.alloc(alloc);
#endif
Let's look at some examples of how we support both interfaces in calls to functions.
In this first example, the max_size member function will use the appropriate allocator object.
size_type max_size () const
#ifdef RWSTD_ALLOCATOR
{ return the_allocator.max_size(); }
#else
{ return node_allocator.max_size(); }
#endif
A second example shows the use of the construct and address allocator functions to construct a