Added equality comparator for Option<T> vs T. From: Jiang Yan Xu <y...@jxu.me> Review: https://reviews.apache.org/r/16332
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0764b7e7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0764b7e7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0764b7e7 Branch: refs/heads/master Commit: 0764b7e752b0ed4075af4ad44e10e6c05f3d9979 Parents: 1c12352 Author: Benjamin Mahler <bmah...@twitter.com> Authored: Thu Dec 19 16:08:07 2013 -0800 Committer: Benjamin Mahler <bmah...@twitter.com> Committed: Thu Dec 19 16:08:07 2013 -0800 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/option.hpp | 10 +++++++++ .../3rdparty/stout/tests/option_tests.cpp | 22 ++++++++++++++++++++ 2 files changed, 32 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0764b7e7/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp index f12c0ca..89b7fc3 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp @@ -75,6 +75,16 @@ public: return !operator == (that); } + bool operator == (const T& that) const + { + return state == SOME && *t == that; + } + + bool operator != (const T& that) const + { + return !operator == (that); + } + bool isSome() const { return state == SOME; } bool isNone() const { return state == NONE; } http://git-wip-us.apache.org/repos/asf/mesos/blob/0764b7e7/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp index bda0610..7ae3b8f 100644 --- a/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp +++ b/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp @@ -68,3 +68,25 @@ TEST(OptionTest, Max) ASSERT_SOME(result); EXPECT_EQ(20, result.get()); } + + +TEST(OptionTest, Comparison) +{ + Option<int> none = None(); + EXPECT_NE(none, 1); + EXPECT_FALSE(none == 1); + + Option<int> one = 1; + EXPECT_EQ(one, 1); + EXPECT_NE(none, one); + EXPECT_FALSE(none == one); + EXPECT_EQ(one, Option<int>::some(1)); + + Option<int> two = 2; + EXPECT_NE(one, two); + + Option<Option<int> > someNone = Option<Option<int> >::some(None()); + Option<Option<int> > noneNone = Option<Option<int> >::none(); + EXPECT_NE(someNone, noneNone); + EXPECT_NE(noneNone, someNone); +}