xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment > Class Template Reference

storage that uses short data optimization More...

#include <memory/SizedStorage.hpp>

+ Inheritance diagram for xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >:

Public Member Functions

 SizedStorage ()=default
 Constructor for an empty storage.
 
template<typename Type , typename... Arguments>
 SizedStorage (std::in_place_type_t< Type >, Arguments &&... arguments)
 In-place constructor for a certain type of object.
 
 ~SizedStorage ()=default
 Destructor.
 
template<typename Type , typename... Arguments>
auto emplace (Arguments &&... arguments) -> Type &
 Creates an object of a certain type in place.
 
template<typename Type >
auto destroy ()
 Destroys an object of a certain type.
 
template<typename Type >
auto get () const -> const Type &
 Gets the value as a certain type.
 
template<typename Type >
auto get () -> Type &
 Gets the value as a certain type.
 

Detailed Description

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
class xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >

storage that uses short data optimization

This class cannot be copied or moved.

Constructor & Destructor Documentation

◆ SizedStorage() [1/2]

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::SizedStorage ( )
default

Constructor for an empty storage.

◆ SizedStorage() [2/2]

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
template<typename Type , typename... Arguments>
xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::SizedStorage ( std::in_place_type_t< Type >  ,
Arguments &&...  arguments 
)

In-place constructor for a certain type of object.

Attention
This function must only be called if the storage currently contains no object.
Template Parameters
Typethe type of the object to create
Parameters
argumentsThe arguments for the Object

◆ ~SizedStorage()

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::~SizedStorage ( )
default

Destructor.

Attention
The destructor does not destroy the contained object, nor does it free any allocated data. You must manually delete any objects you created in the storage using destroy().

Member Function Documentation

◆ destroy()

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
template<typename Type >
auto xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::destroy ( )

Destroys an object of a certain type.

This function calls the destructor of the object and frees any allocated data.

Attention
No type checking is done. It is the responsibility of the caller to ensure that the object is of the correct type.
Template Parameters
Typethe type of the object contained in the storage

◆ emplace()

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
template<typename Type , typename... Arguments>
auto xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::emplace ( Arguments &&...  arguments) -> Type&

Creates an object of a certain type in place.

Attention
This function must only be called if the storage currently contains no object.
Template Parameters
Typethe type of the object to create
Parameters
argumentsThe arguments for the Object
Returns
Returns the object

◆ get() [1/2]

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
template<typename Type >
auto xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::get ( ) -> Type &

Gets the value as a certain type.

Attention
No type checking is done. It is the responsibility of the caller to ensure that the object is of the correct type.
Template Parameters
Typethe type of the object contained in the storage

◆ get() [2/2]

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
template<typename Type >
auto xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::get ( ) const -> const Type &

Gets the value as a certain type.

Attention
No type checking is done. It is the responsibility of the caller to ensure that the object is of the correct type.
Template Parameters
Typethe type of the object contained in the storage

Member Data Documentation

◆ _longData

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
void* xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::_longData

The long data.

◆ _shortData

template<std::size_t kShortDataSize, std::size_t kAlignment = alignof(std::max_align_t)>
std::aligned_storage_t<kShortDataSize, kAlignment> xentara::utils::memory::SizedStorage< kShortDataSize, kAlignment >::_shortData

The short data.