This templated class is used to inherit an allocation member. The rationale for choosing inheritance instead of just having types defining a member for an allocator, lies in the C++ standard's concept of Empty Base Optimization .
The class has a specialization with lang::AllocatorMember<HeapAllocator>, which does not define a member and thus does not increase the footprint of a type that inherits it. With the standard implementation, a reference to the allocator specified with template parameter TAllocator is defined.
Consequently, this type is used to implement templated types that are allocation agnostic. Across ALib, a template parameter specifying an allocator is always named TAllocator. Types with this template parameter, in parallel inherit this type. A prominent example is the string buffer type of module ALib Strings, which usually is known through it's alias name alib::AString, which performs classic heap allocation. Its alias type definition, is given as:
Obviously the original type TString has two template parameters, one specifying the character type, the other specifying the allocator. Now looking at the reference documentation of type TAString, it can be seen that this type AllocatorMember is a protected base class and template parameter TAllocator is forwarded to this base.
TAllocator | The allocator type of the inherited member, as prototyped with Allocator. |
Definition at line 658 of file allocation.hpp.
#include <allocation.hpp>
Public Type Index: | |
using | AllocatorType = TAllocator |
Exposes the allocator type. | |
Public Method Index: | |
AllocatorMember ()=delete | |
Deleted default constructor. (The allocator has to be given with construction) | |
AllocatorMember (TAllocator &pAllocator) noexcept | |
AllocatorInterface< TAllocator > | AI () const noexcept |
TAllocator & | GetAllocator () const noexcept |
Protected Field Index: | |
TAllocator & | allocator |
A reference to the allocator. | |
using AllocatorType = TAllocator |
Exposes the allocator type.
Definition at line 665 of file allocation.hpp.
|
protected |
A reference to the allocator.
Definition at line 661 of file allocation.hpp.
|
inlinenoexcept |
Constructor.
pAllocator | A reference to the allocator to store in member allocator. |
Definition at line 672 of file allocation.hpp.
|
inlinenoexcept |
This is a convenience operator that returns the AllocatorInterface for the stored allocator (by calling Allocator::operator()()).
Definition at line 682 of file allocation.hpp.
|
inlinenoexcept |
Returns the reference to the allocator.
Definition at line 677 of file allocation.hpp.