9 #ifndef CPPCOMMON_FUNCTION_H
10 #define CPPCOMMON_FUNCTION_H
18 template <
class,
size_t Capacity = 1024>
29 template <
class R,
class... Args,
size_t Capacity>
37 template <
class TFunction>
38 Function(TFunction&&
function) noexcept;
41 Function& operator=(std::nullptr_t) noexcept;
44 template <
typename TFunction>
46 template <typename TFunction>
47 Function& operator=(std::reference_wrapper<TFunction> function) noexcept;
50 explicit operator
bool() const noexcept {
return (_manager !=
nullptr); }
53 R operator()(Args... args);
57 template <
class UR,
class... UArgs,
size_t UCapacity>
58 friend void swap(
Function<UR(UArgs...), UCapacity>& function1,
Function<UR(UArgs...), UCapacity>& function2) noexcept;
61 enum class Operation { Clone, Destroy };
63 using Invoker = R (*)(
void*, Args&&...);
64 using Manager = void (*)(
void*,
void*, Operation);
66 static const size_t StorageSize = Capacity -
sizeof(Invoker) -
sizeof(Manager);
67 static const size_t StorageAlign = 8;
69 alignas(StorageAlign) std::byte _data[StorageSize];
73 template <
typename TFunction>
74 static R Invoke(
void* data, Args&&... args) noexcept;
76 template <
typename TFunction>
77 static void Manage(
void* dst,
void* src, Operation op) noexcept;
friend void swap(Function< UR(UArgs...), UCapacity > &function1, Function< UR(UArgs...), UCapacity > &function2) noexcept
Function & operator=(TFunction &&function) noexcept
Allocation free function stub.
Allocation free function inline implementation.
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept