22 template <
typename T,
typename...
Args>
26 static_assert(std::is_same_v<
T, std::decay_t<T>>,
27 "Please pass the raw type, no const or ref");
28 static_assert(
sizeof(
T) <=
sizeof(cache.m_data),
29 "Passed type is too large");
31 std::is_move_assignable_v<T> && std::is_move_constructible_v<T>,
32 "Type needs to be move assignable and move constructible");
34 new (cache.m_data.data())
T(std::forward<Args>(
args)...);
36 cache.m_handler = &static_handler;
43 static_assert(std::is_same_v<
T, std::decay_t<T>>,
44 "Please pass the raw type, no const or ref");
45 static_assert(
sizeof(
T) <=
sizeof(m_data),
"Passed type is too large");
46 return *
reinterpret_cast<T*
>(m_data.data());
50 const T&
get()
const {
51 static_assert(std::is_same_v<
T, std::decay_t<T>>,
52 "Please pass the raw type, no const or ref");
53 static_assert(
sizeof(
T) <=
sizeof(m_data),
"Passed type is too large");
54 return *
reinterpret_cast<const T*
>(m_data.data());
79 virtual void destroy(
void* ptr)
const = 0;
81 virtual void move(
void* from,
void* to)
const = 0;
88 assert(ptr !=
nullptr &&
"Address to destroy is nullptr");
89 T* obj =
static_cast<T*
>(ptr);
94 assert(from !=
nullptr &&
"Source is null");
95 assert(to !=
nullptr &&
"Target is null");
96 T* fromValue =
static_cast<T*
>(from);
100 void move(
void* from,
void* to)
const override {
101 assert(from !=
nullptr &&
"Source is null");
102 assert(to !=
nullptr &&
"Target is null");
104 T* fromValue =
static_cast<T*
>(from);
105 T* toValue =
static_cast<T*
>(to);