28 template <
typename FUNC,
typename ... ARGS>
30 _func(
std::forward<FUNC>(func)),
31 _args(
std::forward<ARGS>(args)...)
34 template <
typename FUNC,
typename ... ARGS>
35 template <
typename ... T>
37 return apply<int>(_func, std::move(_args), std::forward<T>(t)...);
40 template <
typename FUNC,
typename ... ARGS>
44 return Capture<FUNC, ARGS...>(std::forward<FUNC>(func), std::forward<ARGS>(args)...);
51 template <
typename RET,
typename ... ARGS>
53 _callable(reinterpret_cast<void*>(ptr)),
54 _deleter(dummyDeleter)
56 _callback = [](
void* ptr, ARGS...args)->RET {
57 return (*reinterpret_cast<Func>(ptr))(std::forward<ARGS>(args)...);
61 template <
typename RET,
typename ... ARGS>
67 template <
typename RET,
typename ... ARGS>
70 *
this = std::move(other);
73 template <
typename RET,
typename ... ARGS>
78 _callback = other._callback;
79 _deleter = other._deleter;
80 if (other._callable == other._storage.data()) {
81 _storage = other._storage;
82 _callable = _storage.data();
85 _callable = other._callable;
91 template <
typename RET,
typename ... ARGS>
97 other._callable =
nullptr;
102 template <
typename RET,
typename ... ARGS>
108 template <
typename RET,
typename ... ARGS>
109 template <
typename FUNCTOR>
112 initFunctor(std::forward<FUNCTOR>(functor), std::is_lvalue_reference<FUNCTOR>());
115 template <
typename RET,
typename ... ARGS>
116 RET
Function<RET(ARGS...)>::operator()(ARGS...args) {
117 return _callback(_callable, std::forward<ARGS>(args)...);
120 template <
typename RET,
typename ... ARGS>
125 template <
typename RET,
typename ... ARGS>
126 template <
typename FUNCTOR>
127 void Function<RET(ARGS...)>::initFunctor(FUNCTOR&& functor, std::true_type)
129 _callable = std::addressof(functor);
130 _deleter = dummyDeleter;
131 _callback = [](
void* ptr, ARGS...args)->RET {
132 return (*
reinterpret_cast<std::remove_reference_t<FUNCTOR>*
>(ptr))(std::forward<ARGS>(args)...);
136 template <
typename RET,
typename ... ARGS>
137 template <
typename FUNCTOR>
138 void Function<RET(ARGS...)>::initFunctor(FUNCTOR&& functor, std::false_type)
140 if (
sizeof(FUNCTOR) <= size) {
141 new (_storage.data()) FUNCTOR(std::forward<FUNCTOR>(functor));
142 _callable = _storage.data();
143 _deleter = dummyDeleter;
146 _callable =
new char[
sizeof(FUNCTOR)];
147 new (_callable) FUNCTOR(std::forward<FUNCTOR>(functor));
150 _callback = [](
void* ptr, ARGS...args)->RET {
151 return (*
reinterpret_cast<std::remove_reference_t<FUNCTOR>*
>(ptr))(std::forward<ARGS>(args)...);
Definition: quantum_buffer_impl.h:22
Definition: quantum_stl_impl.h:23
Capture(FUNC &&func, ARGS &&...args)
Definition: quantum_capture_impl.h:29
int operator()(T &&...t)
Definition: quantum_capture_impl.h:36
Similar implementation to std::function except that it allows capture of non-copyable types.
Definition: quantum_capture.h:62
Capture< FUNC, ARGS... > makeCapture(FUNC &&func, ARGS &&... args)
Definition: quantum_capture_impl.h:42
Class allowing lambda parameter captures.
Definition: quantum_capture.h:38