aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2019-04-04 23:08:22 +0800
committercrupest <crupest@outlook.com>2019-04-04 23:08:22 +0800
commit6268f3ca09afef812cf288f323cacff22fbfcffc (patch)
tree86e89d3b4212ae069075f799a5278c120e258e73 /include/cru/common
parentdbda5a8e4f0d59ad95be8fc3ee7b21e9122cc474 (diff)
downloadcru-6268f3ca09afef812cf288f323cacff22fbfcffc.tar.gz
cru-6268f3ca09afef812cf288f323cacff22fbfcffc.tar.bz2
cru-6268f3ca09afef812cf288f323cacff22fbfcffc.zip
Finish refactor!!!
Diffstat (limited to 'include/cru/common')
-rw-r--r--include/cru/common/event.hpp11
-rw-r--r--include/cru/common/format.hpp4
2 files changed, 8 insertions, 7 deletions
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 <typename... Args>
- EventHandlerRevoker AddHandler(Args&& args...) {
+ template <typename Arg>
+ EventHandlerRevoker AddHandler(Arg&& handler) {
+ static_assert(std::is_invocable_v<Arg, TArgs...>, "Handler not invocable.");
const auto token = current_token_++;
- handlers_.emplace(token, EventHandler(std::forward<Args>(args)...));
+ handlers_.emplace(token, EventHandler(std::forward<Arg>(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<String>) {
+ details::TypeTag<std::wstring>) {
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<String>) {
+ details::TypeTag<std::wstring>) {
return std::wstring_view(string);
}