ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
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 658 of file allocation.hpp.

#include <allocation.hpp>

Inheritance diagram for 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 AllocatorType = TAllocator

Exposes the allocator type.

Definition at line 665 of file allocation.hpp.

Field Details:

◆ allocator

template<typename TAllocator >
TAllocator& allocator
protected

A reference to the allocator.

Definition at line 661 of file allocation.hpp.

Constructor(s) / Destructor Details:

◆ AllocatorMember()

template<typename TAllocator >
AllocatorMember ( TAllocator & pAllocator)
inlinenoexcept

Constructor.

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

Definition at line 672 of file allocation.hpp.

Method Details:

◆ AI()

template<typename TAllocator >
AllocatorInterface< 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 682 of file allocation.hpp.

◆ GetAllocator()

template<typename TAllocator >
TAllocator & GetAllocator ( ) const
inlinenoexcept

Returns the reference to the allocator.

Returns
The allocator given with construction.

Definition at line 677 of file allocation.hpp.


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