diff --git a/SDL2pp/Private/EventHandlerFunctor.hh b/SDL2pp/Private/EventHandlerFunctor.hh index 1b2f41e..e8daed9 100644 --- a/SDL2pp/Private/EventHandlerFunctor.hh +++ b/SDL2pp/Private/EventHandlerFunctor.hh @@ -30,13 +30,6 @@ namespace SDL2pp { * This is code not to be used directly by users of SDL2pp. */ namespace Private { - /* - * Helper alias to help identify a functor object with the correct signature - * to be used as an event handler. - */ - template - using EventHandlerFunctorSignature = std::function; - /* * Templated class to identify a class that is not an event handler functor. */ @@ -53,7 +46,7 @@ namespace Private { EventHandlerType, EventType, typename std::enable_if< - std::is_convertible>::value + std::is_convertible>::value >::type > : std::true_type { }; } diff --git a/SDL2pp/Private/EventHandlerObject.hh b/SDL2pp/Private/EventHandlerObject.hh index df3d9ee..2e55000 100644 --- a/SDL2pp/Private/EventHandlerObject.hh +++ b/SDL2pp/Private/EventHandlerObject.hh @@ -29,15 +29,6 @@ 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. */ @@ -47,15 +38,18 @@ namespace Private { /* * Templated class to identify a class that is an event handler object, the * way this is done is by verifying that an instance of EventHandlerType has - * the "HandleEvent" member function which received a "const EventType &" - * and returns void. + * the "HandleEvent" member function which received a "EventType" and + * returns void. */ template struct IsEventHandlerObject< EventHandlerType, EventType, typename std::enable_if< - HasEventHandlerMethod::value + std::is_same< + decltype(std::declval().HandleEvent(std::declval())), + void + >::value >::type > : std::true_type { }; } diff --git a/tests/test_eventhandler.cc b/tests/test_eventhandler.cc index b76893f..aafb345 100644 --- a/tests/test_eventhandler.cc +++ b/tests/test_eventhandler.cc @@ -4,66 +4,66 @@ using namespace SDL2pp::Private; -void EventHandlerFunction(const SDL_Event &); +void EventHandlerFunction(SDL_Event); -struct EventHandlerOperator { +struct EventHandlerFunctor { void operator()(SDL_Event); }; struct EventHandler { - void HandleEvent(const SDL_Event &); -}; - -struct InvalidEventHandler { void HandleEvent(SDL_Event); }; +struct InvalidEventHandler { + void handleEvent(SDL_Event); +}; + int main(int, char*[]) { - auto lambda = [](const SDL_Event &) { }; + auto lambda = [](SDL_Event) { }; // Test IsEventHandlerFunctor static_assert( IsEventHandlerFunctor::value, - "IsEventHandlerFunctor<> should accept functions like void(const SDL_Event &)" + "IsEventHandlerFunctor<> should accept functions like void(SDL_Event)" ); static_assert( IsEventHandlerFunctor::value, - "IsEventHandlerFunctor<> should accept functions like void(const SDL_Event &)" + "IsEventHandlerFunctor<> should accept functions like void(SDL_Event)" ); static_assert( - !IsEventHandlerFunctor::value, - "IsEventHandlerFunctor<> shouldn't accept a class with operator(const SDL_Event &)" + IsEventHandlerFunctor::value, + "IsEventHandlerFunctor<> shouldn accept a class with operator(SDL_Event)" ); // Test IsEventHandlerObject static_assert( IsEventHandlerObject::value, - "IsEventHandlerObject<> should accept a class with HandleEvent(const SDL_Event &)" + "IsEventHandlerObject<> should accept a class with HandleEvent(SDL_Event)" ); static_assert( !IsEventHandlerObject::value, - "IsEventHandlerObject<> shouldn't accept a class with a different HandleEvent() signature" + "IsEventHandlerObject<> shouldn't accept a class without a valid signature" ); // Test IsEventHandler static_assert( IsEventHandler::value, - "IsEventHandler<> should accept functions like void(const SDL_Event &)" + "IsEventHandler<> should accept functions like void(SDL_Event)" ); static_assert( IsEventHandler::value, - "IsEventHandler<> should accept functions like void(const SDL_Event &)" + "IsEventHandler<> should accept functions like void(SDL_Event)" + ); + static_assert( + IsEventHandler::value, + "IsEventHandler<> should accept a class with operator(SDL_Event)" ); static_assert( IsEventHandler::value, - "IsEventHandler<> should accept a class with HandleEvent(const SDL_Event &)" - ); - static_assert( - !IsEventHandler::value, - "IsEventHandler<> shouldn't accept a class with operator(const SDL_Event &)" + "IsEventHandler<> should accept a class with HandleEvent(SDL_Event)" ); static_assert( !IsEventHandler::value, - "IsEventHandler<> shouldn't accept a class with a different HandleEvent() signature" + "IsEventHandler<> shouldn't accept a class without a valid signature" ); }