9#ifndef CPPCOMMON_FUNCTION_H
10#define CPPCOMMON_FUNCTION_H
18template <
class,
size_t Capacity = 1024>
29template <
class R,
class... Args,
size_t Capacity>
37 template <
class TFunction>
38 Function(TFunction&& function)
noexcept;
44 template <
typename TFunction>
46 template <
typename TFunction>
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=(std::nullptr_t) noexcept
Function & operator=(std::reference_wrapper< TFunction > function) 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