WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::reference_storage< RawAllocator > Class Template Reference

A StoragePolicy that stores a reference to an allocator. More...

#include <wpi/memory/allocator_storage.hpp>

Public Types

using allocator_type = typename allocator_traits<RawAllocator>::allocator_type
 

Public 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_typeget_allocator () const noexcept
 
 reference_storage (const reference_storage &) noexcept=default
 
reference_storageoperator= (const reference_storage &) noexcept=default
 

Protected Member Functions

 ~reference_storage () noexcept=default
 
bool is_composable () const noexcept
 

Detailed Description

template<class RawAllocator>
class wpi::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.

Member Typedef Documentation

◆ allocator_type

template<class RawAllocator >
using wpi::memory::reference_storage< RawAllocator >::allocator_type = typename allocator_traits<RawAllocator>::allocator_type

Constructor & Destructor Documentation

◆ reference_storage() [1/4]

template<class RawAllocator >
wpi::memory::reference_storage< RawAllocator >::reference_storage ( )
defaultnoexcept

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 >
wpi::memory::reference_storage< RawAllocator >::reference_storage ( const allocator_type & alloc)
inlinenoexcept
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 >
wpi::memory::reference_storage< RawAllocator >::reference_storage ( allocator_type & alloc)
inlinenoexcept
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 >
wpi::memory::reference_storage< RawAllocator >::reference_storage ( const reference_storage< RawAllocator > & )
defaultnoexcept
Effects:
Copies the allocator_reference object. Only copies the pointer to it in the stateful case.

◆ ~reference_storage()

template<class RawAllocator >
wpi::memory::reference_storage< RawAllocator >::~reference_storage ( )
protecteddefaultnoexcept

Member Function Documentation

◆ get_allocator()

template<class RawAllocator >
allocator_type & wpi::memory::reference_storage< RawAllocator >::get_allocator ( ) const
inlinenoexcept
Returns:
Returns a reference to the allocator.
Requires:
The reference must be valid.

◆ is_composable()

template<class RawAllocator >
bool wpi::memory::reference_storage< RawAllocator >::is_composable ( ) const
inlineprotectednoexcept

◆ operator bool()

template<class RawAllocator >
wpi::memory::reference_storage< RawAllocator >::operator bool ( ) const
inlineexplicitnoexcept
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.

◆ operator=()

template<class RawAllocator >
reference_storage & wpi::memory::reference_storage< RawAllocator >::operator= ( const reference_storage< RawAllocator > & )
defaultnoexcept

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