Documentation of memory

( foonathan/memory)

reference_storage< RawAllocator > Class Template Reference

Detailed Description

template<class RawAllocator>
class foonathan::memory::reference_storage< RawAllocator >

A StoragePolicy that stores a reference to an allocator.

For stateful allocators it only stores a pointer to an allocator object and copying/moving only copies the pointer. For stateless allocators it does not store anything, an allocator will be constructed as needed. For allocators that are already shared (determined through is_shared_allocator) it will store the allocator type directly.

Note
It does not take ownership over the allocator in the stateful case, the user has to ensure that the allocator object stays valid. In the other cases the lifetime does not matter.

Typedefs

using allocator_type = typename allocator_traits< RawAllocator >::allocator_type
 

Member Functions

 reference_storage (const allocator_type &alloc) noexcept
 
 reference_storage (allocator_type &alloc) noexcept
 
allocator_type & get_allocator () const noexcept
 
 reference_storage (const reference_storage &) noexcept=default
 
reference_storageoperator= (const reference_storage &) noexcept=default
 

Constructors

§ reference_storage() [1/3]

reference_storage ( const allocator_type &  alloc)
noexcept
Effects:
Creates it from a stateless or shared allocator. It will not store anything, only creates the allocator as needed.
Requires:
The RawAllocator is stateless or shared.

§ reference_storage() [2/3]

reference_storage ( allocator_type &  alloc)
noexcept
Effects:
Creates it from a reference to a stateful allocator. It will store a pointer to this allocator object.
Note
The user has to take care that the lifetime of the reference does not exceed the allocator lifetime.

§ reference_storage() [3/3]

reference_storage ( const reference_storage< RawAllocator > &  )
defaultnoexcept
Effects:
Copies the allocator_reference object. Only copies the pointer to it in the stateful case.

Member Functions

§ operator=()

reference_storage& operator= ( const reference_storage< RawAllocator > &  )
defaultnoexcept
Effects:
Copies the allocator_reference object. Only copies the pointer to it in the stateful case.

§ get_allocator()

allocator_type& get_allocator ( ) const
noexcept
Returns:
Returns a reference to the allocator.