Try Contains enum as an enum class
authorHans Fugal <fugalh@fb.com>
Fri, 21 Feb 2014 18:10:03 +0000 (10:10 -0800)
committerDave Watson <davejwatson@fb.com>
Fri, 28 Feb 2014 22:03:00 +0000 (14:03 -0800)
Summary: Somebody set us up the enum

Test Plan: Unit tests still build and pass. Will see if dependencies build and their unit tests pass. But I don't think anyone uses this outside of `Try` (they shouldn't anyway).

Reviewed By: hannesr@fb.com

FB internal diff: D1184839

folly/wangle/Try-inl.h
folly/wangle/Try.h

index 760ad55193f1ed5e9e95d362936d1281e5c02645..bb3257d6a15e855b90e08007f3f211f4225a7dc2 100644 (file)
@@ -24,9 +24,9 @@ namespace folly { namespace wangle {
 
 template <class T>
 Try<T>::Try(Try<T>&& t) : contains_(t.contains_) {
-  if (contains_ == VALUE) {
+  if (contains_ == Contains::VALUE) {
     new (&value_)T(std::move(t.value_));
-  } else if (contains_ == EXCEPTION) {
+  } else if (contains_ == Contains::EXCEPTION) {
     new (&e_)std::exception_ptr(t.e_);
   }
 }
@@ -35,9 +35,9 @@ template <class T>
 Try<T>& Try<T>::operator=(Try<T>&& t) {
   this->~Try();
   contains_ = t.contains_;
-  if (contains_ == VALUE) {
+  if (contains_ == Contains::VALUE) {
     new (&value_)T(std::move(t.value_));
-  } else if (contains_ == EXCEPTION) {
+  } else if (contains_ == Contains::EXCEPTION) {
     new (&e_)std::exception_ptr(t.e_);
   }
   return *this;
@@ -45,9 +45,9 @@ Try<T>& Try<T>::operator=(Try<T>&& t) {
 
 template <class T>
 Try<T>::~Try() {
-  if (contains_ == VALUE) {
+  if (contains_ == Contains::VALUE) {
     value_.~T();
-  } else if (contains_ == EXCEPTION) {
+  } else if (contains_ == Contains::EXCEPTION) {
     e_.~exception_ptr();
   }
 }
@@ -66,8 +66,8 @@ const T& Try<T>::value() const {
 
 template <class T>
 void Try<T>::throwIfFailed() const {
-  if (contains_ != VALUE) {
-    if (contains_ == EXCEPTION) {
+  if (contains_ != Contains::VALUE) {
+    if (contains_ == Contains::EXCEPTION) {
       std::rethrow_exception(e_);
     } else {
       throw UsingUninitializedTry();
index 2e740c20f475918c07c20ee37442510e45bb240e..d61b4c13e90fa38685f2878e32e8c29ee2b7a342 100644 (file)
@@ -23,7 +23,7 @@ class Try {
   static_assert(!std::is_reference<T>::value,
                 "Try may not be used with reference types");
 
-  enum Contains {
+  enum class Contains {
     VALUE,
     EXCEPTION,
     NOTHING,
@@ -32,10 +32,10 @@ class Try {
  public:
   typedef T element_type;
 
-  Try() : contains_(NOTHING) {}
-  explicit Try(const T& v) : contains_(VALUE), value_(v) {}
-  explicit Try(T&& v) : contains_(VALUE), value_(std::move(v)) {}
-  explicit Try(std::exception_ptr e) : contains_(EXCEPTION), e_(e) {}
+  Try() : contains_(Contains::NOTHING) {}
+  explicit Try(const T& v) : contains_(Contains::VALUE), value_(v) {}
+  explicit Try(T&& v) : contains_(Contains::VALUE), value_(std::move(v)) {}
+  explicit Try(std::exception_ptr e) : contains_(Contains::EXCEPTION), e_(e) {}
 
   // move
   Try(Try<T>&& t);
@@ -58,8 +58,8 @@ class Try {
   const T* operator->() const { return &value(); }
         T* operator->()       { return &value(); }
 
-  bool hasValue() const { return contains_ == VALUE; }
-  bool hasException() const { return contains_ == EXCEPTION; }
+  bool hasValue() const { return contains_ == Contains::VALUE; }
+  bool hasException() const { return contains_ == Contains::EXCEPTION; }
 
  private:
   Contains contains_;