11template <
class R,
class... Args,
size_t Capacity>
12inline Function<R(Args...), Capacity>::Function() noexcept
19template <
class R,
class... Args,
size_t Capacity>
20inline Function<R(Args...), Capacity>::Function(std::nullptr_t) noexcept
25template <
class R,
class... Args,
size_t Capacity>
31 function._manager(&_data, &function._data, Operation::Clone);
32 _invoker = function._invoker;
33 _manager = function._manager;
37template <
class R,
class... Args,
size_t Capacity>
44template <
class R,
class... Args,
size_t Capacity>
45template <
class TFunction>
46inline Function<R(Args...), Capacity>::Function(TFunction&& function) noexcept
49 using function_type =
typename std::decay<TFunction>::type;
52 static_assert((StorageSize >=
sizeof(function_type)),
"Function::StorageSize must be increased!");
53 static_assert(((StorageAlign %
alignof(function_type)) == 0),
"Function::StorageAlign must be adjusted!");
56 new (&_data) function_type(std::forward<TFunction>(function));
58 _invoker = &Invoke<function_type>;
59 _manager = &Manage<function_type>;
62template <
class R,
class... Args,
size_t Capacity>
63inline Function<R(Args...), Capacity>::~Function() noexcept
66 _manager(&_data,
nullptr, Operation::Destroy);
69template <
class R,
class... Args,
size_t Capacity>
70inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(std::nullptr_t)
noexcept
74 _manager(&_data,
nullptr, Operation::Destroy);
81template <
class R,
class... Args,
size_t Capacity>
88template <
class R,
class... Args,
size_t Capacity>
91 Function(std::move(function)).swap(*
this);
95template <
class R,
class... Args,
size_t Capacity>
96template <
typename TFunction>
97inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(TFunction&& function)
noexcept
99 Function(std::forward<TFunction>(function)).swap(*
this);
103template <
class R,
class... Args,
size_t Capacity>
104template <
typename TFunction>
105inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(std::reference_wrapper<TFunction> function)
noexcept
111template <
class R,
class... Args,
size_t Capacity>
112inline R
Function<R(Args...), Capacity>::operator()(Args... args)
115 throw std::bad_function_call();
117 return _invoker(&_data, std::forward<Args>(args)...);
120template <
class R,
class... Args,
size_t Capacity>
121template <
typename TFunction>
122inline R
Function<R(Args...), Capacity>::Invoke(
void* data, Args&&... args)
noexcept
124 TFunction& function = *
static_cast<TFunction*
>(data);
125 return function(std::forward<Args>(args)...);
128template <
class R,
class... Args,
size_t Capacity>
129template <
typename TFunction>
130inline void Function<R(Args...), Capacity>::Manage(
void* dst,
void* src, Operation op)
noexcept
134 case Operation::Clone:
135 new (dst) TFunction(*
static_cast<TFunction*
>(src));
137 case Operation::Destroy:
138 static_cast<TFunction*
>(dst)->~TFunction();
143template <
class R,
class... Args,
size_t Capacity>
147 swap(_data, function._data);
148 swap(_manager, function._manager);
149 swap(_invoker, function._invoker);
152template <
class R,
class... Args,
size_t Capacity>
155 function1.swap(function2);
Allocation free function stub.
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept