Switch includes of PThread to the portability header
[folly.git] / folly / Optional.h
index 61e71c1f2dc86b3709d1e265b9e72b50c8a487ba..5350b2ee5e44d69c55868c0a96e2e24d286a16fb 100644 (file)
@@ -54,6 +54,7 @@
  *  }
  */
 #include <cstddef>
+#include <functional>
 #include <new>
 #include <stdexcept>
 #include <type_traits>
@@ -418,3 +419,16 @@ template<class V> bool operator> (const V& other, const Optional<V>&) = delete;
 ///////////////////////////////////////////////////////////////////////////////
 
 } // namespace folly
+
+// Allow usage of Optional<T> in std::unordered_map and std::unordered_set
+FOLLY_NAMESPACE_STD_BEGIN
+template <class T>
+struct hash<folly::Optional<T>> {
+  size_t operator()(folly::Optional<T> const& obj) const {
+    if (!obj.hasValue()) {
+      return 0;
+    }
+    return hash<typename remove_const<T>::type>()(*obj);
+  }
+};
+FOLLY_NAMESPACE_STD_END