ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::lang::AllocatorMember< TAllocator > Struct Template Reference

Description:

template<typename TAllocator>
struct alib::lang::AllocatorMember< TAllocator >

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:

/// Type alias in namespace \b alib.
using AString= strings::TAString<character, lang::HeapAllocator>;

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.

Note
As explained, this type is useful if allocation agnostic types are needed. This is true for types in this library. However, in many end-user cases, the allocation strategy will be fixed to a certain allocator, and therefore in this case, neither a templated approach, nor the helper-struct is needed.
Template Parameters
TAllocatorThe allocator type of the inherited member, as prototyped with Allocator.

Definition at line 662 of file allocation.inl.

Inheritance diagram for alib::lang::AllocatorMember< TAllocator >:
[legend]

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.
 

Type Definition Details:

◆ AllocatorType

template<typename TAllocator>
using alib::lang::AllocatorMember< TAllocator >::AllocatorType = TAllocator

Exposes the allocator type.

Definition at line 669 of file allocation.inl.

Field Details:

◆ allocator

template<typename TAllocator>
TAllocator& alib::lang::AllocatorMember< TAllocator >::allocator
protected

A reference to the allocator.

Definition at line 665 of file allocation.inl.

Constructor(s) / Destructor Details:

◆ AllocatorMember()

template<typename TAllocator>
alib::lang::AllocatorMember< TAllocator >::AllocatorMember ( TAllocator & pAllocator)
inlinenoexcept

Constructor.

Parameters
pAllocatorA reference to the allocator to store in member allocator.

Definition at line 676 of file allocation.inl.

Method Details:

◆ AI()

template<typename TAllocator>
AllocatorInterface< TAllocator > alib::lang::AllocatorMember< TAllocator >::AI ( ) const
inlinenoexcept

This is a convenience operator that returns the AllocatorInterface for the stored allocator (by calling Allocator::operator()()).

Returns
The allocator interface of the stored allocator.

Definition at line 686 of file allocation.inl.

◆ GetAllocator()

template<typename TAllocator>
TAllocator & alib::lang::AllocatorMember< TAllocator >::GetAllocator ( ) const
inlinenoexcept

Returns the reference to the allocator.

Returns
The allocator given with construction.

Definition at line 681 of file allocation.inl.


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