From be5e0fe012bcf27dca1262057b1b33b7a361a1fc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 9 Jul 2018 15:38:00 +0900 Subject: [PATCH] [stdex.set] Overload '==' operator (#564) This commit introduces 'operator==' overloading over sets. Signed-off-by: Jonghyun Park --- contrib/stdex/include/stdex/set | 18 ++++++++++++++++++ contrib/stdex/src/Set.test.cpp | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/contrib/stdex/include/stdex/set b/contrib/stdex/include/stdex/set index 0273935..d6368d1 100644 --- a/contrib/stdex/include/stdex/set +++ b/contrib/stdex/include/stdex/set @@ -3,6 +3,24 @@ #include +template bool operator==(const std::set &lhs, const std::set &rhs) +{ + if (rhs.size() != lhs.size()) + { + return false; + } + + for (const auto &element : lhs) + { + if (rhs.find(element) == rhs.end()) + { + return false; + } + } + + return true; +} + template std::set operator-(const std::set &lhs, const std::set &rhs) { std::set res; diff --git a/contrib/stdex/src/Set.test.cpp b/contrib/stdex/src/Set.test.cpp index 689a261..3367031 100644 --- a/contrib/stdex/src/Set.test.cpp +++ b/contrib/stdex/src/Set.test.cpp @@ -2,6 +2,12 @@ #include +TEST(SET, operator_eq) +{ + ASSERT_TRUE(std::set({1, 2, 3}) == std::set({1, 2, 3})); + ASSERT_FALSE(std::set({1, 3}) == std::set({1, 2, 3})); +} + TEST(SET, operator_diff) { const std::set lhs{1, 2, 3}; -- 2.7.4