From 1e662f86e2936772585ba67475531a781a0b7006 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Fri, 27 May 2016 13:54:39 -0700 Subject: [PATCH] move comparator to separate class --- src/js_list.hpp | 2 +- src/js_results.hpp | 2 +- src/js_types.hpp | 7 +++++-- src/jsc/jsc_protected.hpp | 21 +++++++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/js_list.hpp b/src/js_list.hpp index 752236a1..472caa9a 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -38,7 +38,7 @@ class List : public realm::List { List(std::shared_ptr r, const ObjectSchema& s, LinkViewRef l) noexcept : realm::List(r, s, l) {} List(const realm::List &l) : realm::List(l) {} - std::map, NotificationToken, Protected> m_notification_tokens; + std::map, NotificationToken, typename Protected::Comparator> m_notification_tokens; }; template diff --git a/src/js_results.hpp b/src/js_results.hpp index 87876e78..1addf422 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -43,7 +43,7 @@ class Results : public realm::Results { Results(SharedRealm r, const ObjectSchema& o, TableView tv, SortOrder s) : realm::Results(r, o, tv, s) {} Results(SharedRealm r, const ObjectSchema& o, LinkViewRef lv, util::Optional q = {}, SortOrder s = {}) : realm::Results(r, o, lv, q, s) {} - std::map, NotificationToken, Protected> m_notification_tokens; + std::map, NotificationToken, typename Protected::Comparator> m_notification_tokens; }; template diff --git a/src/js_types.hpp b/src/js_types.hpp index b70b8f84..ea531723 100644 --- a/src/js_types.hpp +++ b/src/js_types.hpp @@ -247,9 +247,12 @@ class Protected { bool operator!=(const ValueType &) const; bool operator==(const Protected &) const; bool operator!=(const Protected &) const; - bool operator()(const Protected& a, const Protected& b) const; + + struct Comparator { + bool operator()(const Protected& a, const Protected& b) const; + }; }; - + template struct Exception : public std::runtime_error { using ContextType = typename T::Context; diff --git a/src/jsc/jsc_protected.hpp b/src/jsc/jsc_protected.hpp index f3aa87ee..34ac870f 100644 --- a/src/jsc/jsc_protected.hpp +++ b/src/jsc/jsc_protected.hpp @@ -48,9 +48,11 @@ class Protected { return m_context != nullptr; } - bool operator() (const Protected& a, const Protected& b) const { - return a.m_context == b.m_context; - } + struct Comparator { + bool operator() (const Protected& a, const Protected& b) const { + return a.m_context == b.m_context; + } + }; }; template<> @@ -79,12 +81,15 @@ class Protected { operator bool() const { return m_value != nullptr; } - bool operator() (const Protected& a, const Protected& b) const { - if (a.m_context != b.m_context) { - return false; + + struct Comparator { + bool operator() (const Protected& a, const Protected& b) const { + if (a.m_context != b.m_context) { + return false; + } + return JSValueIsStrictEqual(a.m_context, a.m_value, b.m_value); } - return JSValueIsStrictEqual(a.m_context, a.m_value, b.m_value); - } + }; }; template<>