bit::memory
Classes | Public Types | Public Member Functions | Friends | List of all members
bit::memory::allocator_reference Class Reference

A non-owning allocator type that type-erases an underlying allocator. More...

#include <allocator_reference.hpp>

Public Types

using default_alignment = std::integral_constant< std::size_t, 1 >
 

Public Member Functions

template<typename Allocator , typename = std::enable_if_t<is_allocator<std::decay_t<Allocator>>::value && !std::is_same<allocator_reference,std::decay_t<Allocator>>::value>>
 allocator_reference (Allocator &allocator) noexcept
 Constructs an allocator by type erasing the underlying allocator. More...
 
 allocator_reference (const allocator_reference &other) noexcept=default
 Copy-constructs an allocator from an existing one. More...
 
 allocator_reference (allocator_reference &&other) noexcept=default
 Move-constructs an allocator from an existing one. More...
 
allocator_referenceoperator= (const allocator_reference &other) noexcept=default
 Copy-assigns an allocator from an existing one. More...
 
allocator_referenceoperator= (allocator_reference &&other) noexcept=default
 Move-assigns an allocator from an existing one. More...
 
owner< void * > try_allocate (std::size_t size, std::size_t align) noexcept
 Allocates a block from the underlying block allocator. More...
 
owner< void * > allocate (std::size_t size, std::size_t align)
 Allocates a block from the underlying block allocator. More...
 
void deallocate (owner< void *> p, std::size_t n)
 Deallocates a block from the underlying block allocatore. More...
 
allocator_info info () const noexcept
 Gets the amount of bytes used for this allocator. More...
 

Friends

bool operator== (const allocator_reference &, const allocator_reference &) noexcept
 
template<typename >
allocator_reference make_stateless_allocator_reference () noexcept
 Makes an allocator_reference that refers to a stateless allocator. More...
 

Detailed Description

A non-owning allocator type that type-erases an underlying allocator.

This view is non-owning, and thus does not participate in the lifetime of a given allocator.

Note
Since this is type-erased, any static information – such as is_stateless, etc – is lost. It is NOT intended as a drop-in replacement for allocators; only a means of type-erasing the allocator so that underlying APIs need-not require the type of allocator embedded in the class.
Satisfies
Allocator

Definition at line 70 of file allocator_reference.hpp.

Constructor & Destructor Documentation

◆ allocator_reference() [1/3]

template<typename Allocator , typename = std::enable_if_t<is_allocator<std::decay_t<Allocator>>::value && !std::is_same<allocator_reference,std::decay_t<Allocator>>::value>>
bit::memory::allocator_reference::allocator_reference ( Allocator &  allocator)
noexcept

Constructs an allocator by type erasing the underlying allocator.

Parameters
allocatorthe allocator to type-erase

◆ allocator_reference() [2/3]

bit::memory::allocator_reference::allocator_reference ( const allocator_reference other)
defaultnoexcept

Copy-constructs an allocator from an existing one.

Parameters
otherthe other allocator to copy

◆ allocator_reference() [3/3]

bit::memory::allocator_reference::allocator_reference ( allocator_reference &&  other)
defaultnoexcept

Move-constructs an allocator from an existing one.

Parameters
otherthe other allocator to move

Member Function Documentation

◆ allocate()

owner<void*> bit::memory::allocator_reference::allocate ( std::size_t  size,
std::size_t  align 
)

Allocates a block from the underlying block allocator.

Parameters
sizethe size of the allocation
alignthe alignment of the allocation
Returns
the allocated pointer

◆ deallocate()

void bit::memory::allocator_reference::deallocate ( owner< void *>  p,
std::size_t  n 
)

Deallocates a block from the underlying block allocatore.

Parameters
pthe entry to deallocate, originally allocated with a call to allocate
nthe number of entries to destroy

◆ info()

allocator_info bit::memory::allocator_reference::info ( ) const
noexcept

Gets the amount of bytes used for this allocator.

Returns
the amount of bytes used

◆ operator=() [1/2]

allocator_reference& bit::memory::allocator_reference::operator= ( const allocator_reference other)
defaultnoexcept

Copy-assigns an allocator from an existing one.

Parameters
otherthe other allocator to copy
Returns
reference to (*this)

◆ operator=() [2/2]

allocator_reference& bit::memory::allocator_reference::operator= ( allocator_reference &&  other)
defaultnoexcept

Move-assigns an allocator from an existing one.

Parameters
otherthe other allocator to move
Returns
reference to (*this)

◆ try_allocate()

owner<void*> bit::memory::allocator_reference::try_allocate ( std::size_t  size,
std::size_t  align 
)
noexcept

Allocates a block from the underlying block allocator.

Parameters
sizethe size of the allocation
alignthe alignment of the allocation
Returns
the allocated pointer

Friends And Related Function Documentation

◆ make_stateless_allocator_reference

template<typename >
allocator_reference make_stateless_allocator_reference ( )
friend

Makes an allocator_reference that refers to a stateless allocator.

This creates a reference to any stateless allocator that doesn't require an actual instantiation.

Template Parameters
StatelessAllocatorthe type of a stateless allocator

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