numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
num_collect::util::object_storage< T, MinimumAlignment > Class Template Reference

Class of storage of objects. More...

#include <num_collect/util/object_storage.h>

+ Inheritance diagram for num_collect::util::object_storage< T, MinimumAlignment >:
+ Collaboration diagram for num_collect::util::object_storage< T, MinimumAlignment >:

Public Member Functions

 object_storage () noexcept=default
 Constructor.
 
 object_storage (const object_storage &)=delete
 
 object_storage (object_storage &&)=delete
 
 ~object_storage () noexcept
 Destructor.
 
template<typename... Args>
void emplace (Args &&... args)
 Construct an object.
 
auto get_pointer () const noexcept -> const T *
 Get the pointer of the value.
 
auto get_pointer () noexcept -> T *
 Get the pointer of the value.
 
auto get_ref () const noexcept -> const T &
 Get the reference of the value.
 
auto get_ref () noexcept -> T &
 Get the reference of the value.
 
auto operator= (const object_storage &)=delete
 
auto operator= (object_storage &&)=delete
 
void reset () noexcept
 Destruct the object.
 

Private Attributes

bool has_object_ {false}
 Whether this storage has an object. (Defined only in debug build for debugging.)
 
std::array< char, sizeof(T)> storage_ {}
 Storage.
 

Detailed Description

template<typename T, std::size_t MinimumAlignment = cache_line>
class num_collect::util::object_storage< T, MinimumAlignment >

Class of storage of objects.

Warning
This class is similar to std::optional, but this class won't check the existence of objects for any operation. Use this class only when you're writing a custom container by yourself and checking the lifetime of objects by your classes.
Template Parameters
TType of objects.
MinimumAlignmentMinimum alignment.

Definition at line 48 of file object_storage.h.

Constructor & Destructor Documentation

◆ ~object_storage()

template<typename T, std::size_t MinimumAlignment = cache_line>
num_collect::util::object_storage< T, MinimumAlignment >::~object_storage ( )
inlinenoexcept

Destructor.

Definition at line 63 of file object_storage.h.

Member Function Documentation

◆ emplace()

template<typename T, std::size_t MinimumAlignment = cache_line>
template<typename... Args>
void num_collect::util::object_storage< T, MinimumAlignment >::emplace ( Args &&... args)
inline

Construct an object.

Template Parameters
ArgsTypes of arguments of the constructor.
Parameters
[in]argsArguments of the constructor.
Warning
This won't call the destructor if an object exists.

Definition at line 81 of file object_storage.h.

◆ get_pointer() [1/2]

template<typename T, std::size_t MinimumAlignment = cache_line>
auto num_collect::util::object_storage< T, MinimumAlignment >::get_pointer ( ) const -> const T*
inlinenodiscardnoexcept

Get the pointer of the value.

Returns
Pointer.
Warning
This won't check the existence of an object.

Definition at line 146 of file object_storage.h.

◆ get_pointer() [2/2]

template<typename T, std::size_t MinimumAlignment = cache_line>
auto num_collect::util::object_storage< T, MinimumAlignment >::get_pointer ( ) -> T*
inlinenodiscardnoexcept

Get the pointer of the value.

Returns
Pointer.
Warning
This won't check the existence of an object.

Definition at line 131 of file object_storage.h.

◆ get_ref() [1/2]

template<typename T, std::size_t MinimumAlignment = cache_line>
auto num_collect::util::object_storage< T, MinimumAlignment >::get_ref ( ) const -> const T&
inlinenodiscardnoexcept

Get the reference of the value.

Returns
Reference.
Warning
This won't check the existence of an object.

Definition at line 120 of file object_storage.h.

◆ get_ref() [2/2]

template<typename T, std::size_t MinimumAlignment = cache_line>
auto num_collect::util::object_storage< T, MinimumAlignment >::get_ref ( ) -> T&
inlinenodiscardnoexcept

Get the reference of the value.

Returns
Reference.
Warning
This won't check the existence of an object.

Definition at line 111 of file object_storage.h.

◆ reset()

template<typename T, std::size_t MinimumAlignment = cache_line>
void num_collect::util::object_storage< T, MinimumAlignment >::reset ( )
inlinenoexcept

Destruct the object.

Warning
This calls the destructor always.

Definition at line 97 of file object_storage.h.

Member Data Documentation

◆ has_object_

template<typename T, std::size_t MinimumAlignment = cache_line>
bool num_collect::util::object_storage< T, MinimumAlignment >::has_object_ {false}
private

Whether this storage has an object. (Defined only in debug build for debugging.)

Definition at line 163 of file object_storage.h.

◆ storage_

template<typename T, std::size_t MinimumAlignment = cache_line>
std::array<char, sizeof(T)> num_collect::util::object_storage< T, MinimumAlignment >::storage_ {}
private

Storage.

Definition at line 156 of file object_storage.h.


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