Browse Source

delegate::operator==/!= test the instance as a whole now

Michele Caini 6 years ago
parent
commit
e44a71daf2
4 changed files with 9 additions and 21 deletions
  1. 0 2
      TODO
  2. 5 13
      src/entt/signal/delegate.hpp
  3. 1 3
      src/entt/signal/sigh.hpp
  4. 3 3
      test/entt/signal/delegate.cpp

+ 0 - 2
TODO

@@ -27,6 +27,4 @@
 
 TODO
 * registry::sort and registry::respect also for types that are part of a group (untracked items only)
-* remove collector from sigh and use it as a template parameter of sigh::collect
-* sink<F> receives and stores aside a ref to a sigh<F> (public constructor)
 * introduce connection<F> and scoped_connection<F>

+ 5 - 13
src/entt/signal/delegate.hpp

@@ -245,16 +245,12 @@ public:
     }
 
     /**
-     * @brief Checks if the connected functions differ.
-     *
-     * Instances connected to delegates are ignored by this operator. Use the
-     * `instance` member function instead.
-     *
+     * @brief Compares the contents of two delegates.
      * @param other Delegate with which to compare.
-     * @return False if the connected functions differ, true otherwise.
+     * @return False if the two contents differ, true otherwise.
      */
     bool operator==(const delegate<Ret(Args...)> &other) const ENTT_NOEXCEPT {
-        return fn == other.fn;
+        return fn == other.fn && data == other.data;
     }
 
 private:
@@ -264,16 +260,12 @@ private:
 
 
 /**
- * @brief Checks if the connected functions differ.
- *
- * Instances connected to delegates are ignored by this operator. Use the
- * `instance` member function instead.
- *
+ * @brief Compares the contents of two delegates.
  * @tparam Ret Return type of a function type.
  * @tparam Args Types of arguments of a function type.
  * @param lhs A valid delegate object.
  * @param rhs A valid delegate object.
- * @return True if the connected functions differ, false otherwise.
+ * @return True if the two contents differ, false otherwise.
  */
 template<typename Ret, typename... Args>
 bool operator!=(const delegate<Ret(Args...)> &lhs, const delegate<Ret(Args...)> &rhs) ENTT_NOEXCEPT {

+ 1 - 3
src/entt/signal/sigh.hpp

@@ -332,9 +332,7 @@ struct sink<Ret(Args...)> {
         auto &calls = parent->calls;
         delegate<Ret(Args...)> delegate{};
         delegate.template connect<Candidate>(value_or_instance);
-        calls.erase(std::remove_if(calls.begin(), calls.end(), [delegate](const auto &other) {
-            return other == delegate && other.instance() == delegate.instance();
-        }), calls.end());
+        calls.erase(std::remove(calls.begin(), calls.end(), std::move(delegate)), calls.end());
     }
 
     /**

+ 3 - 3
test/entt/signal/delegate.cpp

@@ -136,9 +136,9 @@ TEST(Delegate, Comparison) {
 
     ASSERT_EQ(lhs, (entt::delegate<int(int)>{entt::connect_arg<&delegate_functor::operator()>, &other}));
     ASSERT_NE(lhs.instance(), rhs.instance());
-    ASSERT_FALSE(lhs != rhs);
-    ASSERT_TRUE(lhs == rhs);
-    ASSERT_EQ(lhs, rhs);
+    ASSERT_TRUE(lhs != rhs);
+    ASSERT_FALSE(lhs == rhs);
+    ASSERT_NE(lhs, rhs);
 
     lhs.reset();