ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
Inner Classes | Public Fields | Public Methods | List of all members
StdContMAOptional< T > Struct Template Reference

#include <stdcontainerma.hpp>

Inheritance diagram for StdContMAOptional< T >:
[legend]
Collaboration diagram for StdContMAOptional< T >:
[legend]

Class Description

template<typename T>
struct aworx::lib::monomem::StdContMAOptional< T >


Implementation of std::allocator to be used with container types provided by the C++ standard library.

This allocator only optionally uses monotonic allocation - only if an allocator was given with construction. This has a very small performance impact, hence the non-optional sibling, StdContMA is to be used with types that always use monotonic memory.

Template Parameters
TThe type of objects to be allocated.

Definition at line 324 of file stdcontainerma.hpp.

Inner Classes

struct  rebind
 

Public Fields

MonoAllocatorallocator
 
bool dbgDeallocationWarning
 

Public Methods

constexpr StdContMAOptional ()
 
constexpr StdContMAOptional (const StdContMAOptional &) noexcept=default
 
constexpr StdContMAOptional (MonoAllocator &pAllocator, bool dbgDeallocationWarning=true)
 
constexpr StdContMAOptional (StdContMAOptional &&) noexcept=default
 
template<typename TSibling >
 StdContMAOptional (TSibling &origin)
 
ALIB_NODISCARD T * allocate (size_t n, const void *=nullptr)
 
void deallocate (T *p, std::size_t n)
 
template<typename U >
bool operator!= (const StdContMAOptional< U > &rhs) const noexcept
 
template<typename U >
bool operator== (const StdContMAOptional< U > &rhs) const noexcept
 
- Public Methods inherited from StdContainerMABase< T >
const_pointer address (const_reference x) const noexcept
 
pointer address (reference x) const noexcept
 
template<typename U , typename... Args>
void construct (U *p, Args &&... args)
 
template<typename U >
void destroy (U *p)
 
size_t max_size () const noexcept
 

Additional Inherited Members

- Public Types inherited from StdContainerMABase< T >
using const_pointer = const T *
 
using const_reference = const T &
 
using difference_type = ptrdiff_t
 Type definition as required by C++ library standards.
 
using is_always_equal = std::false_type
 Type definition as required by C++ library standards.
 
using pointer = T *
 
using reference = T &
 
using size_type = size_t
 Type definition as required by C++ library standards.
 
using value_type = T
 Type definition as required by C++ library standards.
 

Constructor & Destructor Documentation

◆ StdContMAOptional() [1/5]

constexpr StdContMAOptional ( )
inlineconstexpr

Default constructor

Definition at line 360 of file stdcontainerma.hpp.

◆ StdContMAOptional() [2/5]

constexpr StdContMAOptional ( const StdContMAOptional< T > &  )
constexprdefaultnoexcept

Defaulted copy constructor

◆ StdContMAOptional() [3/5]

constexpr StdContMAOptional ( StdContMAOptional< T > &&  )
constexprdefaultnoexcept

Defaulted move constructor

◆ StdContMAOptional() [4/5]

StdContMAOptional ( TSibling &  origin)
inline

Copy constructor using an instance of different template type.

Template Parameters
TSiblingThe originating allocator's type (StdContMAOptional<X>).
Parameters
originThe originating allocator of type TSibling .

Definition at line 377 of file stdcontainerma.hpp.

◆ StdContMAOptional() [5/5]

constexpr StdContMAOptional ( MonoAllocator pAllocator,
bool  dbgDeallocationWarning = true 
)
constexpr

Constructor for the initial allocator instantiation.

Parameter dbgDisableDeallocationWarning, which defaults to true might be given after a code is tested to be stict in respect to allocation. (Note: unfortunately, due to the design of std::allocator and its use, this flag can not be changed once a container is constructed. This is why it has to be decided upfront if a warning is to be raised or not).

Parameters
pAllocatorThe recycler for allocations and de-allocations.
dbgDeallocationWarningAs described with this method. Available only in debug builds.

Member Function Documentation

◆ allocate()

ALIB_NODISCARD T* allocate ( size_t  n,
const void *  = nullptr 
)
inline

If allocator is set, passes the allocation request to allocator. Otherwise invokes std::malloc.

Parameters
nThe number of requested objects to allocate storage for.
Returns
Pointer to the first byte of a memory block suitably aligned and sufficient to hold an array of n objects of type T .

Definition at line 445 of file stdcontainerma.hpp.

Here is the call graph for this function:

◆ deallocate()

void deallocate ( T *  p,
std::size_t  n 
)
inline

If allocator is not set, invokes std::free(p). Otherwise does nothing.

Parameters
pPointer to the previously allocated memory.
nThe number of objects allocated.

Definition at line 463 of file stdcontainerma.hpp.

◆ operator!=()

bool operator!= ( const StdContMAOptional< U > &  rhs) const
inlinenoexcept

Comparison operator.

Template Parameters
UThe allocation type of the other allocator.
Parameters
rhsThe right hand side allocator.
Returns
false if this and rhs use the same allocator, true otherwise.

Definition at line 427 of file stdcontainerma.hpp.

◆ operator==()

bool operator== ( const StdContMAOptional< U > &  rhs) const
inlinenoexcept

Comparison operator.

Template Parameters
UThe allocation type of the other allocator.
Parameters
rhsThe right hand side allocator.
Returns
true if this and rhs use the same allocator, false otherwise.

Definition at line 415 of file stdcontainerma.hpp.

Member Data Documentation

◆ allocator

MonoAllocator* allocator

The allocator to use.

Definition at line 347 of file stdcontainerma.hpp.

◆ dbgDeallocationWarning

bool dbgDeallocationWarning

If true warnings about de-allocation of objects are suppressed. this should be set prior to destructing a container that uses this allocator.
Available only in debug builds.

Definition at line 353 of file stdcontainerma.hpp.


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