Refactor coral::closure constraints

This commit is contained in:
kayomn 2023-02-28 16:02:51 +00:00
parent f6daa3c85a
commit 1954f97666

View File

@ -319,20 +319,22 @@ export namespace coral {
* lifetime of any functor assigned to it. * lifetime of any functor assigned to it.
*/ */
template<typename result, typename... arguments> struct closure<result(arguments...)> { template<typename result, typename... arguments> struct closure<result(arguments...)> {
template<typename callable> closure(callable call) requires function_pointer<callable, arguments...> { template<typename callable> closure(callable && call)
this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { requires (functor<callable, arguments...> || function_pointer<callable, arguments...>) {
return (reinterpret_cast<callable>(context))(dispatch_arguments...);
};
this->context = reinterpret_cast<void *>(call); if constexpr (functor<callable, arguments...>) {
} this->dispatch = [](void * context, arguments... dispatch_arguments) -> result {
return (*reinterpret_cast<callable *>(context))(dispatch_arguments...);
};
template<typename callable> closure(callable && call) requires functor<callable, arguments...> { this->context = &call;
this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { } else if constexpr (function_pointer<callable, arguments...>) {
return (*reinterpret_cast<callable *>(context))(dispatch_arguments...); this->dispatch = [](void * context, arguments... dispatch_arguments) -> result {
}; return (reinterpret_cast<callable>(context))(dispatch_arguments...);
};
this->context = &call; this->context = reinterpret_cast<void *>(call);
}
} }
template<typename callable> closure(callable & call) requires functor<callable, arguments...> { template<typename callable> closure(callable & call) requires functor<callable, arguments...> {