From 6268f3ca09afef812cf288f323cacff22fbfcffc Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Apr 2019 23:08:22 +0800 Subject: Finish refactor!!! --- include/cru/common/event.hpp | 11 ++++++----- include/cru/common/format.hpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'include/cru/common') diff --git a/include/cru/common/event.hpp b/include/cru/common/event.hpp index 763f8378..6228d867 100644 --- a/include/cru/common/event.hpp +++ b/include/cru/common/event.hpp @@ -22,7 +22,7 @@ class Event { : resolver_(resolver), token_(token) {} EventHandlerRevokerImpl(const EventHandlerRevokerImpl& other) = default; EventHandlerRevokerImpl(EventHandlerRevokerImpl&& other) = default; - EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) = + EventHandlerRevokerImpl& operator=(const EventHandlerRevokerImpl& other) = default; EventHandlerRevokerImpl& operator=(EventHandlerRevokerImpl&& other) = default; @@ -31,7 +31,7 @@ class Event { void operator()() { const auto true_resolver = resolver_.lock(); if (true_resolver) { - true_resolver()->RemoveHandler(token_); + (*true_resolver)()->RemoveHandler(token_); } } @@ -63,10 +63,11 @@ class Event { return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token)); } - template - EventHandlerRevoker AddHandler(Args&& args...) { + template + EventHandlerRevoker AddHandler(Arg&& handler) { + static_assert(std::is_invocable_v, "Handler not invocable."); const auto token = current_token_++; - handlers_.emplace(token, EventHandler(std::forward(args)...)); + handlers_.emplace(token, EventHandler(std::forward(handler))); return EventHandlerRevoker(EventHandlerRevokerImpl(event_resolver_, token)); } diff --git a/include/cru/common/format.hpp b/include/cru/common/format.hpp index 1fb6863a..f085635a 100644 --- a/include/cru/common/format.hpp +++ b/include/cru/common/format.hpp @@ -83,7 +83,7 @@ inline std::string_view FormatToString(const std::string& string, } inline std::wstring_view FormatToString(const std::wstring_view& string, - details::TypeTag) { + details::TypeTag) { return string; } @@ -93,7 +93,7 @@ inline std::string_view FormatToString(const std::string_view& string, } inline std::wstring_view FormatToString(const wchar_t* string, - details::TypeTag) { + details::TypeTag) { return std::wstring_view(string); } -- cgit v1.2.3