You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mz...@apache.org on 2019/01/09 02:25:00 UTC

[mesos] 01/06: Added rvalue reference Try::get overloads.

This is an automated email from the ASF dual-hosted git repository.

mzhu pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 0f9d46c07d712b41ab90a6347b5901ef62b8e88d
Author: Benjamin Mahler <bm...@apache.org>
AuthorDate: Mon Feb 5 13:35:51 2018 -0800

    Added rvalue reference Try::get overloads.
    
    Review: https://reviews.apache.org/r/65515
---
 3rdparty/stout/include/stout/try.hpp | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/3rdparty/stout/include/stout/try.hpp b/3rdparty/stout/include/stout/try.hpp
index 90f8aed..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_.get().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; }