Make Optional nothrow_default_constructible
authorStepan Palamarchuk <stepan@fb.com>
Wed, 11 Nov 2015 22:22:01 +0000 (14:22 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 11 Nov 2015 23:20:21 +0000 (15:20 -0800)
Summary: It never throws.

Reviewed By: pavlo-fb

Differential Revision: D2640886

fb-gh-sync-id: cd643f8847f4bf5619415731484f91fb07116784

folly/Optional.h
folly/test/OptionalTest.cpp

index def3670..84f5d44 100644 (file)
@@ -96,7 +96,7 @@ class Optional {
   static_assert(!std::is_abstract<Value>::value,
                 "Optional may not be used with abstract types");
 
-  Optional()
+  Optional() noexcept
     : hasValue_(false) {
   }
 
index 42fd492..0c3d9fd 100644 (file)
@@ -21,6 +21,7 @@
 #include <algorithm>
 #include <iomanip>
 #include <string>
+#include <type_traits>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
@@ -542,4 +543,8 @@ TEST(Optional, Exceptions) {
   EXPECT_THROW(empty.value(), OptionalEmptyException);
 }
 
+TEST(Optional, NoThrowDefaultConstructible) {
+  EXPECT_TRUE(std::is_nothrow_default_constructible<Optional<bool>>::value);
+}
+
 }