beautypg.com

How to support both interfaces – HP Integrity NonStop H-Series User Manual

Page 203

background image

size_type max_size () const
{
return alloc_->max_size(sizeof(T));
}
pointer allocate(size_type n, pointer = 0)
{
return static_cast(alloc_->allocate(n*sizeof(T)));
}
void deallocate(pointer p)
{
alloc_->deallocate(p);
}
void construct(pointer p, const T& val)
{
new (p) T(val);
}
void destroy(T* p)
{
((T*)p)->~T();
}
};
class allocator_interface
{
public:
typedef void* pointer;
typedef const void* const_pointer;
};
//
// allocator globals
//
void * operator new(size_t N, my_allocator& a);
inline void * operator new[](size_t N, my_allocator& a);
inline bool operator==(const my_allocator&, const my_allocator&);

How to Support Both Interfaces

Rogue Wave strongly recommends that you implement containers that support both the Standard
C++ Library allocator interface, and our alternative interface. By supporting both interfaces, you
can use allocators now, and take advantage of the standard once it becomes available on your
compiler.

In order to implement both versions of the allocator interface, your containers must have some
mechanism for determining whether the standard interface is available. Rogue Wave provides
the macro RWSTD_ALLOCATOR in stdcomp.h to define whether or not the standard allocator
is available. If RWSTD_ALLOCATOR evaluates to true, your compiler is capable of handling

This manual is related to the following products: