From ab48a57a406f0db467986a1f0752e0e4f9d4971a Mon Sep 17 00:00:00 2001 From: Vraiment Date: Sat, 5 Aug 2017 16:39:02 -0700 Subject: [PATCH] Added enable_if for the EventHandler templates --- SDL2pp/Private/EventHandler.hh | 16 +++++++++------- SDL2pp/Private/EventHandlerFunctor.hh | 4 +++- SDL2pp/Private/EventHandlerObject.hh | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/SDL2pp/Private/EventHandler.hh b/SDL2pp/Private/EventHandler.hh index e8a825e..9ca240d 100644 --- a/SDL2pp/Private/EventHandler.hh +++ b/SDL2pp/Private/EventHandler.hh @@ -91,13 +91,15 @@ namespace Private { struct IsEventHandler< EventHandlerType, EventType, - And< - Or< - IsEventHandlerObject, - IsEventHandlerFunctor - >, - TupleHasType - > + typename std::enable_if< + And< + Or< + IsEventHandlerObject, + IsEventHandlerFunctor + >, + TupleHasType + >::value + >::type > : std::true_type { }; } } diff --git a/SDL2pp/Private/EventHandlerFunctor.hh b/SDL2pp/Private/EventHandlerFunctor.hh index 17ca78b..1b2f41e 100644 --- a/SDL2pp/Private/EventHandlerFunctor.hh +++ b/SDL2pp/Private/EventHandlerFunctor.hh @@ -52,7 +52,9 @@ namespace Private { struct IsEventHandlerFunctor< EventHandlerType, EventType, - std::is_convertible> + typename std::enable_if< + std::is_convertible>::value + >::type > : std::true_type { }; } } diff --git a/SDL2pp/Private/EventHandlerObject.hh b/SDL2pp/Private/EventHandlerObject.hh index 45a486c..df3d9ee 100644 --- a/SDL2pp/Private/EventHandlerObject.hh +++ b/SDL2pp/Private/EventHandlerObject.hh @@ -29,6 +29,15 @@ namespace SDL2pp { * This is code not to be used directly by users of SDL2pp. */ namespace Private { + /* + * Templated class to detect if a given type can handle a given event. + */ + template + struct HasEventHandlerMethod : std::is_same< + decltype(std::declval().HandleEvent(std::declval())), + void + > { }; + /* * Templated class to identify a class that is not an event handler object. */ @@ -45,10 +54,9 @@ namespace Private { struct IsEventHandlerObject< EventHandlerType, EventType, - std::is_same< - decltype(std::declval().HandleEvent(std::declval())), - void - > + typename std::enable_if< + HasEventHandlerMethod::value + >::type > : std::true_type { }; } }