20 template<
typename Out,
typename... In>
23 Out operator()(In... in) {
24 assert(lambda !=
nullptr);
25 return executeLambda(lambda, in...);
34 void generateExecutor(T
const& lambda) {
35 executeLambda = [](
void* lambda, In... arguments) -> Out {
36 return (reinterpret_cast<T*>(lambda))->
operator()(arguments...);
40 void receiveExecutor(
LambdaExecutor<Out(In...)>
const& other) { executeLambda = other.executeLambda; }
44 Out (*executeLambda)(
void*, In...);
47 template<
typename... In>
50 void operator()(In... in) {
51 assert(lambda !=
nullptr);
52 executeLambda(lambda, in...);
61 void generateExecutor(T
const& lambda) {
62 executeLambda = [](
void* lambda, In... arguments) {
63 return (reinterpret_cast<T*>(lambda))->
operator()(arguments...);
67 void receiveExecutor(
LambdaExecutor<
void(In...)>
const& other) { executeLambda = other.executeLambda; }
71 void (*executeLambda)(
void*, In...);
79 template<
typename Out,
typename... In>
82 Lambda() :
LambdaExecutor<Out(In...)>(lambda), lambda(
nullptr), deleteLambda(
nullptr), copyLambda(
nullptr) {}
86 lambda(other.copyLambda ? other.copyLambda(other.lambda) :
nullptr),
87 deleteLambda(other.deleteLambda),
88 copyLambda(other.copyLambda) {
89 this->receiveExecutor(other);
99 if ( deleteLambda !=
nullptr )
100 deleteLambda(lambda);
105 Lambda<Out(In...)>& operator=(
Lambda<Out(In...)>
const& other) {
106 this->lambda = other.copyLambda ? other.copyLambda(other.lambda) :
nullptr;
107 this->receiveExecutor(other);
108 this->deleteLambda = other.deleteLambda;
109 this->copyLambda = other.copyLambda;
114 Lambda<Out(In...)>& operator=(T
const& lambda) {
119 operator bool() {
return lambda !=
nullptr; }
123 void copy_(T
const& lambda) {
124 if ( this->lambda !=
nullptr )
125 deleteLambda(this->lambda);
126 this->lambda =
new T(lambda);
128 this->generateExecutor(lambda);
130 deleteLambda = [](
void* lambda) {
delete reinterpret_cast<T*
>(lambda); };
132 copyLambda = [](
void* lambda) ->
void* {
return lambda ?
new T(*(T*)lambda) :
nullptr; };
136 void (*deleteLambda)(
void*);
137 void* (*copyLambda)(
void*);