non-throwing, non-allocating exception_wrapper
[folly.git] / folly / test / OptionalTest.cpp
index 4a0ef9b37c233308384c5a11e305db6fc576d427..b7484dfa978b6488050eab02470ad15982ea9f67 100644 (file)
  */
 
 #include <folly/Optional.h>
-#include <folly/Portability.h>
 #include <folly/portability/GTest.h>
 
-#include <memory>
-#include <vector>
 #include <algorithm>
 #include <iomanip>
+#include <memory>
 #include <string>
 #include <type_traits>
+#include <unordered_map>
+#include <vector>
 
-#include <glog/logging.h>
 #include <boost/optional.hpp>
 
 using std::unique_ptr;
@@ -460,7 +459,7 @@ TEST(Optional, MakeOptional) {
   EXPECT_EQ(**optIntPtr, 3);
 }
 
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
 # pragma clang diagnostic push
 # pragma clang diagnostic ignored "-Wself-move"
 #endif
@@ -475,7 +474,7 @@ TEST(Optional, SelfAssignment) {
   ASSERT_TRUE(b.hasValue() && b.value() == 23333333);
 }
 
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
 # pragma clang diagnostic pop
 #endif
 
@@ -545,4 +544,12 @@ TEST(Optional, TriviallyDestructible) {
   EXPECT_TRUE(std::is_trivially_destructible<Optional<int>>::value);
   EXPECT_FALSE(std::is_trivially_destructible<Optional<WithDestructor>>::value);
 }
+
+TEST(Optional, Hash) {
+  // Test it's usable in std::unordered map (compile time check)
+  std::unordered_map<Optional<int>, Optional<int>> obj;
+  // Also check the std::hash template can be instantiated by the compiler
+  std::hash<Optional<int>>()(none);
+  std::hash<Optional<int>>()(3);
+}
 }