Add get and getError methods to ErrorOr.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 8 Jan 2014 21:17:09 +0000 (21:17 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 8 Jan 2014 21:17:09 +0000 (21:17 +0000)
ErrorOr is modeled after boost::optional which has a get method.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198792 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ErrorOr.h

index 26af1e8c8004ee8279ce601c7a0fac862f38cc72..21ab4e721dcffc7ef21f3f4b3cc097f10daa43b0 100644 (file)
@@ -178,10 +178,17 @@ public:
     return HasError ? 0 : unspecified_bool_true;
   }
 
+  T &get() { return *getStorage(); }
+  const T &get() const { return const_cast<ErrorOr<T> >(this)->get(); }
+
   operator llvm::error_code() const {
     return HasError ? *getErrorStorage() : llvm::error_code::success();
   }
 
+  error_code getError() const {
+    return HasError ? *getErrorStorage() : error_code::success();
+  }
+
   pointer operator ->() {
     return toPointer(getStorage());
   }