Overview
This template supplies a uniform interface for allocator types.
Details
The allocator_traits class template provides the standardized way to access various properties of Allocators. The standard containers and other standard library components access allocators through this template, which makes it possible to use any class type as an allocator, as long as the user-provided specialization of std::allocator_traits implements all required functionality.
Syntax
The syntax is as below.
template< class Alloc> struct allocator_traits;
Name | Description |
---|---|
Alloc | The allocator type, aliased as member type allocator_type. |
Members
The default, non-specialized, std::allocator_traits contains the following members.
member type | definition |
---|---|
allocator_type | Alloc |
value_type | Alloc::value_type |
pointer | Alloc::pointer if present, otherwise value_type* |
const_pointer | Alloc::const_pointer if present, otherwise std::pointer_traits<pointer>::rebind<const value_type> |
void_pointer | Alloc::void_pointer if present, otherwise std::pointer_traits<pointer>::rebind<void> |
const_void_pointer | Alloc::const_void_pointer if present, otherwise std::pointer_traits<pointer>::rebind<const void> |
difference_type | Alloc::difference_type if present, otherwise std::pointer_traits<pointer>::difference_type |
size_type | Alloc::size_type if present, otherwise std::make_unsigned<difference_type>::type |
propagate_on_container_copy_assignment | Alloc::propagate_on_container_copy_assignment if present, otherwise std::false_type |
propagate_on_container_move_assignment | Alloc::propagate_on_container_move_assignment if present, otherwise std::false_type |
propagate_on_container_swap | Alloc::propagate_on_container_swap if present, otherwise std::false_type |
is_always_equal | Alloc::is_always_equal if present, otherwise std::is_empty<Alloc>::type |
Member alias templates
These are defined on alias template.
member type | definition |
---|---|
rebind_alloc<T> | Alloc::rebind<T>::other if present, otherwise AllocTemplate<T,Args> |
value_type | Alloc::value_type |
Functionality
Methods
The following static methods are defined.Name | Description |
---|---|
allocator_type allocator_traits::select_on_container_copy_construction (const allocator_traits::& a) | If possible, obtains the copy-constructed version of the allocator a, by calling a.select_on_container_copy_construction(). If the above is not possible (e.g. Alloc does not have the member function select_on_container_copy_construction()), then returns a, unmodified. |
| Uses the allocator a to allocate n * sizeof(value_type) bytes of uninitialized storage. An array of type value_type[n] is created in the storage, but none of its elements are constructed.
|
void allocator_traits::deallocate (allocator_type& a, pointer p, size_type n) | Uses the allocator a to deallocate the storage referenced by p, by calling a.deallocate(p, n). |
size_type allocator_traits::max_size (allocator_type& a) | If possible, obtains the maximum theoretically possible allocation size from the allocator a, by calling a.max_size(). If the above is not possible (e.g., a does not have the member function max_size()), then returns std::numeric_limits<size_type>::max() / sizeof(value_type). |
template< class U, class... Args > void allocator_traits::construct (allocator_type& a, U* p, Args&&... args ) | Using allocator a, constructs an object of type T in allocated uninitialized storage pointed to by p, using a.construct(p, std::forward<Args>(args)...). If it's not possible, global placement-new is used. ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...). |
template< class U > void allocator_traits::destroy (allocator_type& a, U* p ) | Calls the destructor of the object pointed to by p. If possible, does so by calling a.destroy(p). If not possible (e.g. a does not have the member function destroy()), then calls the destructor of *p directly, as p->~U(). |
The following Example 14 demonstrates usage of specialized allocator class that uses windows shared memory.
No comments:
Post a Comment