Versioning for Thrift, remove thrift/lib/cpp/config.h
[folly.git] / folly / Optional.h
index f85fbf6b600a2e949d985292848cb824727d16e7..eb8de160c8903d47bda5757c4e28b783bd402ae1 100644 (file)
@@ -61,6 +61,7 @@
 
 #include <boost/operators.hpp>
 
+#include <folly/Portability.h>
 
 namespace folly {
 
@@ -112,15 +113,17 @@ class Optional {
     }
   }
 
-  /* implicit */ Optional(const None&)
+  /* implicit */ Optional(const None&) noexcept
     : hasValue_(false) {
   }
 
-  /* implicit */ Optional(Value&& newValue) {
+  /* implicit */ Optional(Value&& newValue)
+    noexcept(std::is_nothrow_move_constructible<Value>::value) {
     construct(std::move(newValue));
   }
 
-  /* implicit */ Optional(const Value& newValue) {
+  /* implicit */ Optional(const Value& newValue)
+    noexcept(std::is_nothrow_copy_constructible<Value>::value) {
     construct(newValue);
   }
 
@@ -133,11 +136,13 @@ class Optional {
   }
 
   void assign(Optional&& src) {
-    if (src.hasValue()) {
-      assign(std::move(src.value()));
-      src.clear();
-    } else {
-      clear();
+    if (this != &src) {
+      if (src.hasValue()) {
+        assign(std::move(src.value()));
+        src.clear();
+      } else {
+        clear();
+      }
     }
   }