mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
Update any.h
This commit is contained in:
parent
2081dcf979
commit
e8830e6407
@ -103,31 +103,4 @@ struct function<Ret(Params...)>{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct lightfunction;
|
||||
|
||||
template<typename Ret, typename... Params>
|
||||
struct lightfunction<Ret(Params...)>{
|
||||
void* _impl;
|
||||
Ret (*_wrapper)(void*, Params...);
|
||||
|
||||
lightfunction() : _impl(nullptr), _wrapper(nullptr) {}
|
||||
|
||||
explicit operator bool() const { return _wrapper != nullptr; }
|
||||
|
||||
template<typename F>
|
||||
lightfunction(const F& f){
|
||||
_impl = (F*)(&f);
|
||||
_wrapper = [](void* impl, Params... params) -> Ret{
|
||||
F* f = (F*)(impl);
|
||||
return (*f)(std::forward<Params>(params)...);
|
||||
};
|
||||
}
|
||||
|
||||
Ret operator()(Params... params) const{
|
||||
if(!_wrapper) throw std::runtime_error("empty function");
|
||||
return _wrapper(_impl, std::forward<Params>(params)...);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace pkpy
|
Loading…
x
Reference in New Issue
Block a user