9 #ifndef OS_DELEGATE_HPP_
10 #define OS_DELEGATE_HPP_
45 template <
class Interface,
class Implementation,
class StorageType>
48 static_assert(std::is_base_of<Interface, Implementation>::value,
"Implementation must derive from Interface");
49 static_assert(
sizeof(Implementation) <=
sizeof(StorageType),
"Handle size not large enough");
50 static_assert((
FW_HANDLE_ALIGNMENT %
alignof(Implementation)) == 0,
"Handle alignment invalid");
52 Implementation*
interface = new (aligned_new_memory) Implementation;
88 template <
class Interface,
class Implementation,
class StorageType>
89 inline Interface*
makeDelegate(StorageType& aligned_new_memory,
const Interface* to_copy) {
90 const Implementation* copy_me =
reinterpret_cast<const Implementation*
>(to_copy);
92 static_assert(std::is_base_of<Interface, Implementation>::value,
"Implementation must derive from Interface");
93 static_assert(
sizeof(Implementation) <=
sizeof(aligned_new_memory),
"Handle size not large enough");
94 static_assert((
FW_HANDLE_ALIGNMENT %
alignof(Implementation)) == 0,
"Handle alignment invalid");
96 Implementation*
interface = nullptr;
97 if (to_copy ==
nullptr) {
98 interface = new (aligned_new_memory) Implementation;
100 interface = new (aligned_new_memory) Implementation(*copy_me);
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
Interface * makeDelegate(StorageType &aligned_new_memory)
Make a delegate of type Interface using Implementation without copy-constructor support (generic func...