bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::null_allocator Class Reference

An allocator that only ever serves nullptr. More...

#include <null_allocator.hpp>

Public Types

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

Public Member Functions

 null_allocator ()=default
 Default-constructs a null_allocator.
 
 null_allocator (null_allocator &&other) noexcept=default
 Move-constructs a null_allocator from another allocator. More...
 
 null_allocator (const null_allocator &other) noexcept=default
 Copy-constructs a null_allocator from another allocator. More...
 
null_allocatoroperator= (null_allocator &&other) noexcept=default
 Move-assigns a null_allocator from another allocator. More...
 
null_allocatoroperator= (const null_allocator &other) noexcept=default
 Copy-assigns a null_allocator from another allocator. More...
 
owner< void * > try_allocate (std::size_t size, std::size_t align, std::size_t offset=0) noexcept
 Allocates a null pointer. More...
 
void deallocate (owner< void *> p, std::size_t n) noexcept
 Deallocates a pointer previously allocated with a call to allocate. More...
 
bool owns (const void *p) const noexcept
 Checks if the pointer p is contained in the null_allocator. More...
 
bool owns (std::nullptr_t) const noexcept
 Checks if nullptr is part of this allocator. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Detailed Description

An allocator that only ever serves nullptr.

As is expected, the size and alignment of the allocation will always be ignored, since this only returns nullptr.

Invoking null_allocator::deallocate on a pointer has no effect, but is considered bad-practice, since this allocator could never produce a valid allocation.

Satisfies
ExtendedAllocator
Satisfies
Stateless

Definition at line 61 of file null_allocator.hpp.

Constructor & Destructor Documentation

◆ null_allocator() [1/2]

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

Move-constructs a null_allocator from another allocator.

Parameters
otherthe other null_allocator to move

◆ null_allocator() [2/2]

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

Copy-constructs a null_allocator from another allocator.

Parameters
otherthe other null_allocator to copy

Member Function Documentation

◆ deallocate()

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

Deallocates a pointer previously allocated with a call to allocate.

Parameters
pthe pointer to deallocate
nthe number of entries previously allocated

◆ info()

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

Gets the info about this allocator.

This defaults to 'null_allocator'. Use a named_null_allocator to override this

Returns
the info for this allocator

◆ operator=() [1/2]

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

Move-assigns a null_allocator from another allocator.

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

◆ operator=() [2/2]

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

Copy-assigns a null_allocator from another allocator.

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

◆ owns() [1/2]

bool bit::memory::null_allocator::owns ( const void *  p) const
noexcept

Checks if the pointer p is contained in the null_allocator.

Parameters
pthe pointer to check
Returns
true if p is nullptr

◆ owns() [2/2]

bool bit::memory::null_allocator::owns ( std::nullptr_t  ) const
noexcept

Checks if nullptr is part of this allocator.

Returns
true

◆ try_allocate()

owner<void*> bit::memory::null_allocator::try_allocate ( std::size_t  size,
std::size_t  align,
std::size_t  offset = 0 
)
noexcept

Allocates a null pointer.

Parameters
sizethe size of the allocation
alignthe alignment of the allocation
Returns
nullptr

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