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 <bmah...@apache.org>
Authored: Mon Feb 5 13:35:51 2018 -0800
Committer: Benjamin Mahler <bmah...@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; }
 

Reply via email to