You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/06/14 13:17:55 UTC
[2/6] mesos git commit: Enable Option to hold a noncopyable type.
Enable Option to hold a noncopyable type.
Review: https://reviews.apache.org/r/35431
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fb0a6d9e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fb0a6d9e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fb0a6d9e
Branch: refs/heads/master
Commit: fb0a6d9e69282073ad3bcd68ab32c49c817d01b3
Parents: 654cabf
Author: Michael Park <mc...@gmail.com>
Authored: Sun Jun 14 03:26:56 2015 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Jun 14 04:12:01 2015 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/option.hpp | 27 ++++++++++++++
.../3rdparty/stout/tests/option_tests.cpp | 39 ++++++++++++++++++++
2 files changed, 66 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/fb0a6d9e/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 8d5217a..3d9b7a7 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp
@@ -39,6 +39,8 @@ public:
Option(const T& _t) : state(SOME), t(_t) {}
+ Option(T&& _t) : state(SOME), t(std::move(_t)) {}
+
template <typename U>
Option(const U& u) : state(SOME), t(u) {}
@@ -47,6 +49,9 @@ public:
template <typename U>
Option(const _Some<U>& some) : state(SOME), t(some.t) {}
+ template <typename U>
+ Option(_Some<U>&& some) : state(SOME), t(std::move(some.t)) {}
+
Option(const Option<T>& that) : state(that.state)
{
if (that.isSome()) {
@@ -54,6 +59,13 @@ public:
}
}
+ Option(Option<T>&& that) : state(std::move(that.state))
+ {
+ if (that.isSome()) {
+ new (&t) T(std::move(that.t));
+ }
+ }
+
~Option()
{
if (isSome()) {
@@ -76,6 +88,21 @@ public:
return *this;
}
+ Option<T>& operator = (Option<T>&& that)
+ {
+ if (this != &that) {
+ if (isSome()) {
+ t.~T();
+ }
+ state = std::move(that.state);
+ if (that.isSome()) {
+ new (&t) T(std::move(that.t));
+ }
+ }
+
+ return *this;
+ }
+
bool operator == (const Option<T>& that) const
{
return (isNone() && that.isNone()) ||
http://git-wip-us.apache.org/repos/asf/mesos/blob/fb0a6d9e/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 f1ae80a..0e5d451 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp
@@ -101,3 +101,42 @@ TEST(OptionTest, NonConstReference)
s.get() += " world";
EXPECT_EQ("hello world", s.get());
}
+
+
+struct NonCopyable
+{
+ NonCopyable() = default;
+ NonCopyable(NonCopyable&&) = default;
+ NonCopyable(const NonCopyable& that) = delete;
+};
+
+
+TEST(OptionTest, NonCopyable)
+{
+ Option<NonCopyable> o1(NonCopyable{});
+ ASSERT_SOME(o1);
+
+ o1 = NonCopyable();
+ ASSERT_SOME(o1);
+
+ o1 = None();
+ ASSERT_NONE(o1);
+
+ Option<NonCopyable> o2 = NonCopyable();
+ ASSERT_SOME(o2);
+
+ o2 = NonCopyable();
+ ASSERT_SOME(o2);
+
+ o2 = None();
+ ASSERT_NONE(o2);
+
+ Option<NonCopyable> o3 = None();
+ ASSERT_NONE(o3);
+
+ Option<NonCopyable> o4 = Some(NonCopyable());
+ ASSERT_SOME(o4);
+
+ o4 = Some(NonCopyable());
+ ASSERT_SOME(o4);
+}