Versioning for Thrift, remove thrift/lib/cpp/config.h
[folly.git] / folly / Optional.h
index 4295e271532f5466ab7cc1c992a073823fa38b2a..eb8de160c8903d47bda5757c4e28b783bd402ae1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -61,6 +61,7 @@
 
 #include <boost/operators.hpp>
 
+#include <folly/Portability.h>
 
 namespace folly {
 
@@ -91,7 +92,9 @@ class Optional {
     : hasValue_(false) {
   }
 
-  Optional(const Optional& src) {
+  Optional(const Optional& src)
+    noexcept(std::is_nothrow_copy_constructible<Value>::value) {
+
     if (src.hasValue()) {
       construct(src.value());
     } else {
@@ -99,7 +102,9 @@ class Optional {
     }
   }
 
-  Optional(Optional&& src) {
+  Optional(Optional&& src)
+    noexcept(std::is_nothrow_move_constructible<Value>::value) {
+
     if (src.hasValue()) {
       construct(std::move(src.value()));
       src.clear();
@@ -108,19 +113,21 @@ 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);
   }
 
-  ~Optional() {
+  ~Optional() noexcept {
     clear();
   }
 
@@ -129,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();
+      }
     }
   }
 
@@ -167,12 +176,16 @@ class Optional {
     return *this;
   }
 
-  Optional& operator=(Optional &&other) {
+  Optional& operator=(Optional &&other)
+    noexcept (std::is_nothrow_move_assignable<Value>::value) {
+
     assign(std::move(other));
     return *this;
   }
 
-  Optional& operator=(const Optional &other) {
+  Optional& operator=(const Optional &other)
+    noexcept (std::is_nothrow_copy_assignable<Value>::value) {
+
     assign(other);
     return *this;
   }