Refactor coral::closure constraints
This commit is contained in:
parent
f6daa3c85a
commit
1954f97666
@ -319,20 +319,22 @@ export namespace coral {
|
||||
* lifetime of any functor assigned to it.
|
||||
*/
|
||||
template<typename result, typename... arguments> struct closure<result(arguments...)> {
|
||||
template<typename callable> closure(callable call) requires function_pointer<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...> || function_pointer<callable, 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->dispatch = [](void * context, arguments... dispatch_arguments) -> result {
|
||||
return (*reinterpret_cast<callable *>(context))(dispatch_arguments...);
|
||||
};
|
||||
this->context = &call;
|
||||
} else if constexpr (function_pointer<callable, 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...> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user