|
|
@ -1,6 +1,6 @@ |
|
|
|
#pragma once
|
|
|
|
#include "gp/exception.hpp"
|
|
|
|
|
|
|
|
#include "gp/algorithm/tmp_manip.hpp"
|
|
|
|
namespace gp{ |
|
|
|
|
|
|
|
template <typename> |
|
|
@ -10,6 +10,8 @@ namespace gp{ |
|
|
|
class function<ret(args...)>{ |
|
|
|
struct virtual_callable |
|
|
|
{ |
|
|
|
virtual void inplace_copy(char*) = 0; |
|
|
|
virtual virtual_callable* all_copy() = 0; |
|
|
|
virtual ~virtual_callable() = default; |
|
|
|
virtual ret operator() (args...) = 0; |
|
|
|
}; |
|
|
@ -22,8 +24,18 @@ namespace gp{ |
|
|
|
: internal_representation{func} |
|
|
|
{} |
|
|
|
|
|
|
|
callable(callable&) = default; |
|
|
|
|
|
|
|
virtual ~callable() override = default; |
|
|
|
|
|
|
|
virtual void inplace_copy(char* ptr) override { |
|
|
|
new(ptr) callable(*this); |
|
|
|
} |
|
|
|
|
|
|
|
virtual virtual_callable* all_copy() override { |
|
|
|
return new callable(*this); |
|
|
|
} |
|
|
|
|
|
|
|
ret operator() (args... arg_list) override |
|
|
|
{ |
|
|
|
return internal_representation(arg_list...); |
|
|
@ -59,16 +71,21 @@ namespace gp{ |
|
|
|
delete self.functor; |
|
|
|
} |
|
|
|
} |
|
|
|
if constexpr (sizeof(callable<T>) <= sizeof(self)) |
|
|
|
{ |
|
|
|
new((void*)self.inplace) callable(t); |
|
|
|
state = (state_t)(ACTIVE | SOO); |
|
|
|
} |
|
|
|
else |
|
|
|
if(t.state | ACTIVE) |
|
|
|
{ |
|
|
|
self.functor = new callable<T>(t); |
|
|
|
state = (state_t)(ACTIVE | NO_SOO); |
|
|
|
if constexpr (sizeof(callable<T>) <= sizeof(self)) |
|
|
|
{ |
|
|
|
t.self.functor->inplace_copy(self.inplace); |
|
|
|
state = (state_t)(ACTIVE | SOO); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
self.functor = t.self.functor->all_copy(); |
|
|
|
state = (state_t)(ACTIVE | NO_SOO); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
state = INACTIVE; |
|
|
|
} |
|
|
|
|
|
|
|
function() |
|
|
@ -91,6 +108,20 @@ namespace gp{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
template<> |
|
|
|
function<function>(function& t) { |
|
|
|
if(t.state & SOO) |
|
|
|
{ |
|
|
|
t.self.functor->inplace_copy(self.inplace); |
|
|
|
state = (state_t)(ACTIVE | SOO); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
self.functor = t.self.functor->all_copy(); |
|
|
|
state = (state_t)(ACTIVE | NO_SOO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
function(T& t) |
|
|
|
{ |
|
|
|