[stdex.set] Overload '==' operator (#564)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 9 Jul 2018 06:38:00 +0000 (15:38 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 9 Jul 2018 06:38:00 +0000 (15:38 +0900)
This commit introduces 'operator==' overloading over sets.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/stdex/include/stdex/set
contrib/stdex/src/Set.test.cpp

index 0273935..d6368d1 100644 (file)
@@ -3,6 +3,24 @@
 
 #include <set>
 
+template <typename T> bool operator==(const std::set<T> &lhs, const std::set<T> &rhs)
+{
+  if (rhs.size() != lhs.size())
+  {
+    return false;
+  }
+
+  for (const auto &element : lhs)
+  {
+    if (rhs.find(element) == rhs.end())
+    {
+      return false;
+    }
+  }
+
+  return true;
+}
+
 template <typename T> std::set<T> operator-(const std::set<T> &lhs, const std::set<T> &rhs)
 {
   std::set<T> res;
index 689a261..3367031 100644 (file)
@@ -2,6 +2,12 @@
 
 #include <gtest/gtest.h>
 
+TEST(SET, operator_eq)
+{
+  ASSERT_TRUE(std::set<int>({1, 2, 3}) == std::set<int>({1, 2, 3}));
+  ASSERT_FALSE(std::set<int>({1, 3}) == std::set<int>({1, 2, 3}));
+}
+
 TEST(SET, operator_diff)
 {
   const std::set<int> lhs{1, 2, 3};