libbmb
Modern implementation of STL
Loading...
Searching...
No Matches
bmb::AllocatorTraits< Alloc > Class Template Reference

Unifined interface for allocators. More...

#include <allocator.h>

Public Types

using allocator_type = Alloc
 

Static Public Member Functions

template<typename T , typename... Args>
static void construct (Alloc &alloc, T *ptr, Args &&... args)
 Forwards given arguments to allocator's construct method if present. Otherwise uses placement new.
 
template<typename T >
static void destroy (Alloc &alloc, T *ptr)
 Destroys object throgh alloctor if destroy method is present. Otherwise calls ~T()
 
template<typename T >
static Tallocate (Alloc &alloc, size_t n)
 Allocates given number of objects using allocator.
 
template<typename T >
static void deallocate (Alloc &alloc, T *ptr, size_t n)
 Deallocates memory under ptr through allocator.
 

Detailed Description

template<typename Alloc>
class bmb::AllocatorTraits< Alloc >

Unifined interface for allocators.

All callers to any allocator should do it throw this class-proxy. It predefines some default methods in case a allocator dosn't do it. Otherwise it calls the allocator's method.

Member Typedef Documentation

◆ allocator_type

template<typename Alloc >
using bmb::AllocatorTraits< Alloc >::allocator_type = Alloc

Member Function Documentation

◆ allocate()

template<typename Alloc >
template<typename T >
static T * bmb::AllocatorTraits< Alloc >::allocate ( Alloc alloc,
size_t  n 
)
inlinestatic

Allocates given number of objects using allocator.

Parameters
allocAllocator to use for allocation
nNumber of objects to allocate
Returns
Pointer to the allocated memory
Exceptions
Sameas alloc.allocate(...)

◆ construct()

template<typename Alloc >
template<typename T , typename... Args>
static void bmb::AllocatorTraits< Alloc >::construct ( Alloc alloc,
T ptr,
Args &&...  args 
)
inlinestatic

Forwards given arguments to allocator's construct method if present. Otherwise uses placement new.

Parameters
allocAllocator to use in construction
ptrPointer to raw memory where to construct
args...Arguments to pass in constructor
Exceptions
Sameas alloc.construct(...) if present. Otherwise same specification as new

◆ deallocate()

template<typename Alloc >
template<typename T >
static void bmb::AllocatorTraits< Alloc >::deallocate ( Alloc alloc,
T ptr,
size_t  n 
)
inlinestatic

Deallocates memory under ptr through allocator.

Parameters
allocAllocator to use in deallocation
ptrPointer to the previously allocated memory
nNumber of objects to deallocate
Exceptions
Samespecification as alloc.deallocate()

◆ destroy()

template<typename Alloc >
template<typename T >
static void bmb::AllocatorTraits< Alloc >::destroy ( Alloc alloc,
T ptr 
)
inlinestatic

Destroys object throgh alloctor if destroy method is present. Otherwise calls ~T()

Parameters
allocAllocator to use in destruction
ptrPointer to object to destroy
Exceptions
Ifallocator has method destroy - throws the same. Otherwise doesn't throw(in assumption object destructor doesn't throw)

The documentation for this class was generated from the following file: