You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2018/02/23 23:03:46 UTC

[1/2] mesos git commit: Added rvalue reference Try::get overloads.

Repository: mesos
Updated Branches:
  refs/heads/master 874dc2cd5 -> 538abbc21


Added rvalue reference Try::get overloads.

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


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

Branch: refs/heads/master
Commit: 538abbc21c9dcb675930aaaf61eb5df10ed62205
Parents: 05cf02c
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Feb 5 13:35:51 2018 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Feb 23 15:01:57 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/try.hpp | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/538abbc2/3rdparty/stout/include/stout/try.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/try.hpp b/3rdparty/stout/include/stout/try.hpp
index bcd55b9..30cce7e 100644
--- a/3rdparty/stout/include/stout/try.hpp
+++ b/3rdparty/stout/include/stout/try.hpp
@@ -70,19 +70,10 @@ public:
   bool isSome() const { return data.isSome(); }
   bool isError() const { return data.isNone(); }
 
-  const T& get() const
-  {
-    if (!data.isSome()) {
-      assert(error_.isSome());
-      ABORT("Try::get() but state == ERROR: " + error_->message);
-    }
-    return data.get();
-  }
-
-  T& get()
-  {
-    return const_cast<T&>(static_cast<const Try&>(*this).get());
-  }
+  T& get() & { return get(*this); }
+  const T& get() const & { return get(*this); }
+  T&& get() && { return get(std::move(*this)); }
+  const T&& get() const && { return get(std::move(*this)); }
 
   const T* operator->() const { return &get(); }
   T* operator->() { return &get(); }
@@ -101,6 +92,16 @@ public:
 private:
   static const std::string& error_impl(const Error& err) { return err.message; }
 
+  template <typename Self>
+  static auto get(Self&& self) -> decltype(std::forward<Self>(self).data.get())
+  {
+    if (!self.data.isSome()) {
+      assert(self.error_.isSome());
+      ABORT("Try::get() but state == ERROR: " + self.error_->message);
+    }
+    return std::forward<Self>(self).data.get();
+  }
+
   template <typename Err>
   static const Err& error_impl(const Err& err) { return err; }
 


[2/2] mesos git commit: Introduced a CHECK_NOTERROR macro.

Posted by bm...@apache.org.
Introduced a CHECK_NOTERROR macro.

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


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

Branch: refs/heads/master
Commit: 05cf02c7472184f7e102b704c0609f0047685bd8
Parents: 874dc2c
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Feb 5 13:32:37 2018 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Feb 23 15:01:57 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/check.hpp | 79 ++++++++++++++++++++++++++---
 1 file changed, 73 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/05cf02c7/3rdparty/stout/include/stout/check.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/check.hpp b/3rdparty/stout/include/stout/check.hpp
index 6a33579..7651150 100644
--- a/3rdparty/stout/include/stout/check.hpp
+++ b/3rdparty/stout/include/stout/check.hpp
@@ -23,9 +23,15 @@
 #include <stout/error.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
-#include <stout/result.hpp>
 #include <stout/some.hpp>
-#include <stout/try.hpp>
+
+
+template <typename T>
+class Result;
+
+template <typename T, typename E>
+class Try;
+
 
 // A generic macro to facilitate definitions of CHECK_*, akin to CHECK.
 // This appends the error if possible to the end of the log message,
@@ -102,6 +108,67 @@ const T& _check_not_none(
       (expression))
 
 
+// A private helper for CHECK_NOTERROR which is similar to the
+// CHECK_NOTNULL provided by glog.
+template <typename T, typename E>
+T&& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    Try<T, E>&& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return std::move(t).get();
+}
+
+
+template <typename T, typename E>
+T& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    Try<T, E>& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return t.get();
+}
+
+
+template <typename T, typename E>
+const T& _check_not_error(
+    const char* file,
+    int line,
+    const char* message,
+    const Try<T, E>& t) {
+  if (t.isError()) {
+    google::LogMessageFatal(
+        file,
+        line,
+        new std::string(
+            std::string(message) + ": " + Error(t.error()).message));
+  }
+  return t.get();
+}
+
+
+#define CHECK_NOTERROR(expression) \
+  _check_not_error( \
+      __FILE__, \
+      __LINE__, \
+      "'" #expression "' Must be SOME", \
+      (expression))
+
+
 // Private structs/functions used for CHECK_*.
 
 template <typename T>
@@ -116,8 +183,8 @@ Option<Error> _check_some(const Option<T>& o)
 }
 
 
-template <typename T>
-Option<Error> _check_some(const Try<T>& t)
+template <typename T, typename E>
+Option<Error> _check_some(const Try<T, E>& t)
 {
   if (t.isError()) {
     return Error(t.error());
@@ -168,8 +235,8 @@ Option<Error> _check_none(const Result<T>& r)
 }
 
 
-template <typename T>
-Option<Error> _check_error(const Try<T>& t)
+template <typename T, typename E>
+Option<Error> _check_error(const Try<T, E>& t)
 {
   if (t.isSome()) {
     return Error("is SOME");