Repository: mesos
Updated Branches:
  refs/heads/master 9002a748d -> b40d4e8dd


Added -> operators for Option, Try, Result.

See MESOS-2757.

Review: https://reviews.apache.org/r/36868


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a7727015
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a7727015
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a7727015

Branch: refs/heads/master
Commit: a7727015b023997a06e387ec806bc4badbc49c8d
Parents: 9002a74
Author: Ben Mahler <[email protected]>
Authored: Tue Aug 25 16:16:37 2015 -0400
Committer: Joris Van Remoortere <[email protected]>
Committed: Tue Aug 25 16:41:26 2015 -0400

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/option.hpp     | 21 ++++++++------
 .../3rdparty/stout/include/stout/result.hpp     |  8 ++++++
 .../3rdparty/stout/include/stout/try.hpp        |  8 +++---
 .../3rdparty/stout/tests/option_tests.cpp       | 10 +++++++
 .../3rdparty/stout/tests/result_tests.cpp       | 14 +++++++++
 .../3rdparty/stout/tests/try_tests.cpp          | 30 ++++++++++++++++++++
 6 files changed, 78 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/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 283fdac..db5e332 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/option.hpp
@@ -103,6 +103,18 @@ public:
     return *this;
   }
 
+  bool isSome() const { return state == SOME; }
+  bool isNone() const { return state == NONE; }
+
+  const T& get() const { assert(isSome()); return t; }
+  T& get() { assert(isSome()); return t; }
+
+  const T* operator->() const { return &get(); }
+  T* operator->() { return &get(); }
+
+  // This must return a copy to avoid returning a reference to a temporary.
+  T getOrElse(const T& _t) const { return isNone() ? _t : t; }
+
   bool operator==(const Option<T>& that) const
   {
     return (isNone() && that.isNone()) ||
@@ -124,15 +136,6 @@ public:
     return !(*this == that);
   }
 
-  bool isSome() const { return state == SOME; }
-  bool isNone() const { return state == NONE; }
-
-  const T& get() const { assert(isSome()); return t; }
-  T& get() { assert(isSome()); return t; }
-
-  // This must return a copy to avoid returning a reference to a temporary.
-  T getOrElse(const T& _t) const { return isNone() ? _t : t; }
-
 private:
   enum State
   {

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
index d5c562d..86f6238 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/result.hpp
@@ -112,6 +112,14 @@ public:
     return data.get().get();
   }
 
+  T& get()
+  {
+    return const_cast<T &>(static_cast<const Result &>(*this).get());
+  }
+
+  const T* operator->() const { return &get(); }
+  T* operator->() { return &get(); }
+
   const std::string& error() const { assert(isError()); return data.error(); }
 
 private:

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
index 0e0e19e..2049f69 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/try.hpp
@@ -81,12 +81,12 @@ public:
 
   T& get()
   {
-    if (!data.isSome()) {
-      ABORT("Try::get() but state == ERROR: " + message);
-    }
-    return data.get();
+    return const_cast<T &>(static_cast<const Try &>(*this).get());
   }
 
+  const T* operator->() const { return &get(); }
+  T* operator->() { return &get(); }
+
   const std::string& error() const { assert(data.isNone()); return message; }
 
 private:

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/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 0c3f89b..657aaef 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/option_tests.cpp
@@ -119,6 +119,16 @@ TEST(OptionTest, NonConstReference)
 }
 
 
+TEST(OptionTest, ArrowOperator)
+{
+  Option<string> s = string("hello");
+  EXPECT_EQ(5u, s->size());
+
+  s->clear();
+  EXPECT_TRUE(s->empty());
+}
+
+
 struct NonCopyable
 {
   NonCopyable() = default;

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
index 0a38106..f109e97 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/result_tests.cpp
@@ -12,6 +12,8 @@
  * limitations under the License.
  */
 
+#include <string>
+
 #include <gmock/gmock.h>
 
 #include <stout/error.hpp>
@@ -19,6 +21,8 @@
 #include <stout/result.hpp>
 #include <stout/try.hpp>
 
+using std::string;
+
 // Verify Try to Result conversion.
 TEST(ResultTest, TryToResultConversion)
 {
@@ -45,3 +49,13 @@ TEST(ResultTest, TryToResultConversion)
   EXPECT_ERROR(result);
   EXPECT_EQ(result.error(), tryError.error());
 }
+
+
+TEST(ResultTest, ArrowOperator)
+{
+  Result<string> s = string("hello");
+  EXPECT_EQ(5u, s->size());
+
+  s->clear();
+  EXPECT_TRUE(s->empty());
+}

http://git-wip-us.apache.org/repos/asf/mesos/blob/a7727015/3rdparty/libprocess/3rdparty/stout/tests/try_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/try_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/try_tests.cpp
new file mode 100644
index 0000000..0a12639
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/try_tests.cpp
@@ -0,0 +1,30 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <stout/try.hpp>
+
+using std::string;
+
+TEST(TryTest, ArrowOperator)
+{
+  Try<string> s = string("hello");
+  EXPECT_EQ(5u, s->size());
+
+  s->clear();
+  EXPECT_TRUE(s->empty());
+}

Reply via email to