Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch > Class Template Reference

Implements pimpl idiom without dynamic memory allocation. More...

#include <fast_pimpl.hpp>

Public Member Functions

template<typename... Args>
 explicit (sizeof...(Args)==1) const expr FastPimpl(Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >)
 
constexpr FastPimpl (const FastPimpl &other) noexcept(noexcept(FastPimpl(std::declval< const T & >())))
 
constexpr FastPimpl (FastPimpl &&other) noexcept(noexcept(FastPimpl(std::declval< T && >())))
 
constexpr ~FastPimpl () noexcept(noexcept(std::destroy_at(std::declval< T * >())))
 
constexpr FastPimploperator= (const FastPimpl &rhs) noexcept(noexcept(std::declval< T & >()=std::declval< const T & >()))
 
constexpr FastPimploperator= (FastPimpl &&rhs) noexcept(noexcept(std::declval< T & >()=std::declval< T && >()))
 
constexpr FastPimploperator= (const T &value) noexcept(noexcept(std::declval< T & >()=std::declval< const T & >()))
 Copy-assigns from a T instance.
 
constexpr FastPimploperator= (T &&value) noexcept(noexcept(std::declval< T & >()=std::declval< T && >()))
 Move-assigns from a T instance.
 
constexpr T * operator-> () noexcept
 
constexpr const T * operator-> () const noexcept
 
constexpr T & operator* () noexcept
 
constexpr const T & operator* () const noexcept
 

Detailed Description

template<class T, size_t Size, size_t Alignment, bool RequireStrictMatch = false>
class helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >

Implements pimpl idiom without dynamic memory allocation.

FastPimpl doesn't require memory allocation or indirect memory access. You must manually set object size and alignment when instantiating FastPimpl.

Template Parameters
TThe implementation type
SizeThe size in bytes to allocate for T
AlignmentThe alignment requirement for T
RequireStrictMatchIf true, requires exact size/alignment match

Definition at line 24 of file fast_pimpl.hpp.

Constructor & Destructor Documentation

◆ FastPimpl() [1/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::FastPimpl ( const FastPimpl< T, Size, Alignment, RequireStrictMatch > &  other)
inlineconstexprnoexcept

Definition at line 32 of file fast_pimpl.hpp.

33 : FastPimpl(*other) {}
constexpr FastPimpl(const FastPimpl &other) noexcept(noexcept(FastPimpl(std::declval< const T & >())))

◆ FastPimpl() [2/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::FastPimpl ( FastPimpl< T, Size, Alignment, RequireStrictMatch > &&  other)
inlineconstexprnoexcept

Definition at line 35 of file fast_pimpl.hpp.

36 : FastPimpl(std::move(*other)) {}

◆ ~FastPimpl()

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch>
constexpr helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::~FastPimpl ( )
constexprnoexcept

Definition at line 73 of file fast_pimpl.hpp.

74 {
75 ValidateConstraints();
76 std::destroy_at(Impl());
77}

Member Function Documentation

◆ explicit()

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
template<typename... Args>
helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::explicit ( sizeof...  Args = = 1) const &&
inlinenoexcept

Definition at line 27 of file fast_pimpl.hpp.

28 {
29 std::construct_at(Impl(), std::forward<Args>(args)...);
30 }

◆ operator*() [1/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr const T & helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator* ( ) const
inlineconstexprnoexcept

Definition at line 61 of file fast_pimpl.hpp.

61{ return *Impl(); }

◆ operator*() [2/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr T & helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator* ( )
inlineconstexprnoexcept

Definition at line 60 of file fast_pimpl.hpp.

60{ return *Impl(); }

◆ operator->() [1/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr const T * helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator-> ( ) const
inlineconstexprnoexcept

Definition at line 59 of file fast_pimpl.hpp.

59{ return Impl(); }

◆ operator->() [2/2]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch = false>
constexpr T * helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator-> ( )
inlineconstexprnoexcept

Definition at line 58 of file fast_pimpl.hpp.

58{ return Impl(); }

◆ operator=() [1/4]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch>
constexpr auto helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator= ( const FastPimpl< T, Size, Alignment, RequireStrictMatch > &  rhs)
constexprnoexcept

Definition at line 80 of file fast_pimpl.hpp.

81 {
82 if (this != &rhs) [[likely]] {
83 *Impl() = *rhs;
84 }
85 return *this;
86}

◆ operator=() [2/4]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch>
constexpr auto helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator= ( const T &  value)
constexprnoexcept

Copy-assigns from a T instance.

Parameters
valueSource value
Returns
Reference to this instance

Definition at line 98 of file fast_pimpl.hpp.

99 {
100 if (Impl() != &value) [[likely]] {
101 *Impl() = value;
102 }
103 return *this;
104}

◆ operator=() [3/4]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch>
constexpr auto helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator= ( FastPimpl< T, Size, Alignment, RequireStrictMatch > &&  rhs)
constexprnoexcept

Definition at line 89 of file fast_pimpl.hpp.

90 {
91 if (this != &rhs) [[likely]] {
92 *Impl() = std::move(*rhs);
93 }
94 return *this;
95}

◆ operator=() [4/4]

template<class T , size_t Size, size_t Alignment, bool RequireStrictMatch>
constexpr auto helios::utils::FastPimpl< T, Size, Alignment, RequireStrictMatch >::operator= ( T &&  value)
constexprnoexcept

Move-assigns from a T instance.

Parameters
valueSource value
Returns
Reference to this instance

Definition at line 107 of file fast_pimpl.hpp.

108 {
109 if (Impl() != &value) [[likely]] {
110 *Impl() = std::move(value);
111 }
112 return *this;
113}