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 648 of file allocation.inl.
Public Type Index: | |
| using | AllocatorType = TAllocator |
| Exposes the allocator type. | |
Public Method Index: | |
| template<typename TIf = TAllocator> requires std::is_default_constructible_v<TIf> | |
| AllocatorMember () | |
| AllocatorMember (TAllocator &pAllocator) noexcept | |
| AllocatorInterface< TAllocator > | AI () const noexcept |
| TAllocator & | GetAllocator () const noexcept |
Protected Field Index: | |
| TAllocator * | allocator |
| The allocator stored. | |
| using alib::lang::AllocatorMember< TAllocator >::AllocatorType = TAllocator |
Exposes the allocator type.
Definition at line 655 of file allocation.inl.
|
protected |
The allocator stored.
Definition at line 651 of file allocation.inl.
|
inline |
Default constructor. Only applicable if the allocator type is default-constructible, i.e., HeapAllocator.
| TIf | Defaulted, must not be given. |
Definition at line 662 of file allocation.inl.
|
inlinenoexcept |
Constructor.
| pAllocator | A reference to the allocator to store in member allocator. |
Definition at line 666 of file allocation.inl.
|
inlinenoexcept |
This is a convenience operator that returns the AllocatorInterface for the stored allocator (by calling Allocator::operator()()).
Definition at line 676 of file allocation.inl.
|
inlinenoexcept |
Returns the reference to the allocator.
Definition at line 671 of file allocation.inl.