From 1954f976665a751a90da002ca153d068b1187252 Mon Sep 17 00:00:00 2001 From: kayomn Date: Tue, 28 Feb 2023 16:02:51 +0000 Subject: [PATCH] Refactor coral::closure constraints --- source/coral.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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 {