reference_storage< RawAllocator > Class Template Reference
Allocator storage

## 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 () noexcept=default
| Default constructor.
| reference_storage (const allocator_type &alloc) noexcept
| reference_storage (allocator_type &alloc) noexcept
| operator bool () const noexcept
allocator_type & | get_allocator () const noexcept
| reference_storage (const reference_storage &) noexcept=default
reference_storage & | operator= (const reference_storage &) noexcept=default

## Constructors

## reference_storage() [1/4]

template<class RawAllocator >

reference_storage | ( |  | ) |

default noexcept

Default constructor.

Effects:
  If the allocator is stateless, this has no effect and the object is usable as an allocator. If the allocator is stateful, creates an invalid reference without any associated allocator. Then it must not be used. If the allocator is shared, default constructs the shared allocator. If the shared allocator does not have a default constructor, this constructor is ill-formed.

## reference_storage() [2/4]

template<class RawAllocator >

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() [3/4]

template<class RawAllocator >

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() [4/4]

template<class RawAllocator >

reference_storage | ( | const reference_storage< RawAllocator > & |  | ) |

default noexcept

Effects:
  Copies the `allocator_reference` object. Only copies the pointer to it in the stateful case.

## Member Functions

## operator=()

template<class RawAllocator >

reference_storage & operator= | ( | const reference_storage< RawAllocator > & |  | ) |

default noexcept

Effects:
  Copies the `allocator_reference` object. Only copies the pointer to it in the stateful case.

## operator bool()

template<class RawAllocator >

operator bool | ( |  | ) | const

explicit noexcept

Returns:
  Whether or not the reference is valid. It is only invalid, if it was created by the default constructor and the allocator is stateful.

## get_allocator()

template<class RawAllocator >

allocator_type & get_allocator | ( |  | ) | const

noexcept

Returns:
  Returns a reference to the allocator.

Requires:
  The reference must be valid.