Added enable_if for the EventHandler templates

This commit is contained in:
Vraiment 2017-08-05 16:39:02 -07:00
parent a52074324e
commit ab48a57a40
3 changed files with 24 additions and 12 deletions

View File

@ -91,13 +91,15 @@ namespace Private {
struct IsEventHandler< struct IsEventHandler<
EventHandlerType, EventHandlerType,
EventType, EventType,
And< typename std::enable_if<
Or< And<
IsEventHandlerObject<EventHandlerType, EventType>, Or<
IsEventHandlerFunctor<EventHandlerType, EventType> IsEventHandlerObject<EventHandlerType, EventType>,
>, IsEventHandlerFunctor<EventHandlerType, EventType>
TupleHasType<EventType, ValidEventTypes> >,
> TupleHasType<EventType, ValidEventTypes>
>::value
>::type
> : std::true_type { }; > : std::true_type { };
} }
} }

View File

@ -52,7 +52,9 @@ namespace Private {
struct IsEventHandlerFunctor< struct IsEventHandlerFunctor<
EventHandlerType, EventHandlerType,
EventType, EventType,
std::is_convertible<EventHandlerType, EventHandlerFunctorSignature<EventType>> typename std::enable_if<
std::is_convertible<EventHandlerType, EventHandlerFunctorSignature<EventType>>::value
>::type
> : std::true_type { }; > : std::true_type { };
} }
} }

View File

@ -29,6 +29,15 @@ namespace SDL2pp {
* This is code not to be used directly by users of SDL2pp. * This is code not to be used directly by users of SDL2pp.
*/ */
namespace Private { namespace Private {
/*
* Templated class to detect if a given type can handle a given event.
*/
template <typename EventHandlerType, typename EventType>
struct HasEventHandlerMethod : std::is_same<
decltype(std::declval<EventHandlerType>().HandleEvent(std::declval<const EventType &>())),
void
> { };
/* /*
* Templated class to identify a class that is not an event handler object. * Templated class to identify a class that is not an event handler object.
*/ */
@ -45,10 +54,9 @@ namespace Private {
struct IsEventHandlerObject< struct IsEventHandlerObject<
EventHandlerType, EventHandlerType,
EventType, EventType,
std::is_same< typename std::enable_if<
decltype(std::declval<EventHandlerType>().HandleEvent(std::declval<const EventType &>())), HasEventHandlerMethod<EventHandlerType, EventType>::value
void >::type
>
> : std::true_type { }; > : std::true_type { };
} }
} }