14 static void delete_data(
void* data ) noexcept
17 delete static_cast< T*
>( data );
21 static void* copy_data(
void* data )
23 return data ?
new T( *static_cast< T* >( data ) ) :
nullptr;
29 template <
class T, std::enable_if_t< !std::is_constructible<
33 : del_( &delete_data<
std::decay_t< T > > ),
34 copy_data_( ©_data<
std::decay_t< T > > ),
35 data_( new
std::decay_t< T >(
std::forward< T >( value ) ) )
39 template <
class T, std::enable_if_t< !std::is_constructible<
44 return *
this = Storage( std::forward< T >( value ) );
53 : del_( other.del_ ), copy_data_( other.copy_data_ ),
54 data_( other.data_ == nullptr ? nullptr : other.copy() )
59 : del_( other.del_ ), copy_data_( other.copy_data_ ), data_( other.data_ )
61 other.data_ =
nullptr;
64 type_erased_storage_t&
operator=(
const type_erased_storage_t& other )
68 copy_data_ = other.copy_data_;
69 data_ = ( other.data_ ==
nullptr ? nullptr : other.copy() );
73 type_erased_storage_t&
operator=( type_erased_storage_t&& other ) noexcept
77 copy_data_ = other.copy_data_;
79 other.data_ =
nullptr;
87 return *
static_cast< T*
>( data_ );
91 const T&
get()
const noexcept
94 return *
static_cast< const T*
>( data_ );
97 explicit operator bool() const noexcept
99 return data_ !=
nullptr;
103 void reset() noexcept
105 if ( data_ !=
nullptr )
114 return copy_data_( data_ );
117 using delete_fn = void ( * )(
void* );
118 using copy_fn =
void* (*)(
void* );
119 delete_fn del_ =
nullptr;
120 copy_fn copy_data_ =
nullptr;
121 void* data_ =
nullptr;
type_erased_storage_t(T &&value)
Definition: type_erased_storage.hpp:32
type_erased_storage_t & operator=(T &&value)
Definition: type_erased_storage.hpp:41
Definition: beat_duration.hpp:106
#define SEQUENCER_ASSERT(cond)
Definition: assert.hpp:8
type_erased_storage_t(type_erased_storage_t &&other) noexcept
Definition: type_erased_storage.hpp:58
type_erased_storage_t & operator=(const type_erased_storage_t &other)
Definition: type_erased_storage.hpp:64
Definition: type_erased_storage.hpp:11
~type_erased_storage_t()
Definition: type_erased_storage.hpp:47
type_erased_storage_t(const type_erased_storage_t &other)
Definition: type_erased_storage.hpp:52
type_erased_storage_t() noexcept=default
type_erased_storage_t & operator=(type_erased_storage_t &&other) noexcept
Definition: type_erased_storage.hpp:73