From: Hans Fugal Date: Fri, 21 Feb 2014 18:10:03 +0000 (-0800) Subject: Try Contains enum as an enum class X-Git-Tag: v0.22.0~674 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=53bcd8886d54be5da19ac2dddf46532f0d287fbd;p=folly.git Try Contains enum as an enum class 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 --- diff --git a/folly/wangle/Try-inl.h b/folly/wangle/Try-inl.h index 760ad551..bb3257d6 100644 --- a/folly/wangle/Try-inl.h +++ b/folly/wangle/Try-inl.h @@ -24,9 +24,9 @@ namespace folly { namespace wangle { template Try::Try(Try&& 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 Try& Try::operator=(Try&& 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& Try::operator=(Try&& t) { template Try::~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::value() const { template void Try::throwIfFailed() const { - if (contains_ != VALUE) { - if (contains_ == EXCEPTION) { + if (contains_ != Contains::VALUE) { + if (contains_ == Contains::EXCEPTION) { std::rethrow_exception(e_); } else { throw UsingUninitializedTry(); diff --git a/folly/wangle/Try.h b/folly/wangle/Try.h index 2e740c20..d61b4c13 100644 --- a/folly/wangle/Try.h +++ b/folly/wangle/Try.h @@ -23,7 +23,7 @@ class Try { static_assert(!std::is_reference::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); @@ -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_;