diff --git a/source/coral.cpp b/source/coral.cpp index 1b3f364..139c8a1 100755 --- a/source/coral.cpp +++ b/source/coral.cpp @@ -319,20 +319,22 @@ export namespace coral { * lifetime of any functor assigned to it. */ template struct closure { - template closure(callable call) requires function_pointer { - this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { - return (reinterpret_cast(context))(dispatch_arguments...); - }; + template closure(callable && call) + requires (functor || function_pointer) { - this->context = reinterpret_cast(call); - } + if constexpr (functor) { + this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { + return (*reinterpret_cast(context))(dispatch_arguments...); + }; - template closure(callable && call) requires functor { - this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { - return (*reinterpret_cast(context))(dispatch_arguments...); - }; + this->context = &call; + } else if constexpr (function_pointer) { + this->dispatch = [](void * context, arguments... dispatch_arguments) -> result { + return (reinterpret_cast(context))(dispatch_arguments...); + }; - this->context = &call; + this->context = reinterpret_cast(call); + } } template closure(callable & call) requires functor {