11 template <
class R,
class... Args,
size_t Capacity>
19 template <
class R,
class... Args,
size_t Capacity>
25 template <
class R,
class... Args,
size_t Capacity>
31 function._manager(&_data, &
function._data, Operation::Clone);
32 _invoker =
function._invoker;
33 _manager =
function._manager;
37 template <
class R,
class... Args,
size_t Capacity>
44 template <
class R,
class... Args,
size_t Capacity>
45 template <
class TFunction>
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>;
62 template <
class R,
class... Args,
size_t Capacity>
63 inline Function<R(Args...), Capacity>::~Function() noexcept
66 _manager(&_data,
nullptr, Operation::Destroy);
69 template <
class R,
class... Args,
size_t Capacity>
70 inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(std::nullptr_t) noexcept
74 _manager(&_data,
nullptr, Operation::Destroy);
81 template <
class R,
class... Args,
size_t Capacity>
88 template <
class R,
class... Args,
size_t Capacity>
91 Function(std::move(
function)).swap(*
this);
95 template <
class R,
class... Args,
size_t Capacity>
96 template <
typename TFunction>
97 inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(TFunction&&
function) noexcept
99 Function(std::forward<TFunction>(
function)).swap(*
this);
103 template <
class R,
class... Args,
size_t Capacity>
104 template <
typename TFunction>
105 inline Function<R(Args...), Capacity>&
Function<R(Args...), Capacity>::operator=(std::reference_wrapper<TFunction>
function) noexcept
111 template <
class R,
class... Args,
size_t Capacity>
112 inline R
Function<R(Args...), Capacity>::operator()(Args... args)
115 throw std::bad_function_call();
117 return _invoker(&_data, std::forward<Args>(args)...);
120 template <
class R,
class... Args,
size_t Capacity>
121 template <
typename TFunction>
122 inline 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)...);
128 template <
class R,
class... Args,
size_t Capacity>
129 template <
typename TFunction>
130 inline 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();
143 template <
class R,
class... Args,
size_t Capacity>
147 swap(_data,
function._data);
148 swap(_manager,
function._manager);
149 swap(_invoker,
function._invoker);
152 template <
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
void swap(Function< R(Args...), Capacity > &function1, Function< R(Args...), Capacity > &function2) noexcept