* }
*/
#include <cstddef>
+#include <functional>
#include <new>
#include <stdexcept>
#include <type_traits>
struct StorageTriviallyDestructible {
// The union trick allows to initialize the Optional's memory,
- // so that compiler/tools don't complain about unitialized memory,
+ // so that compiler/tools don't complain about uninitialized memory,
// without actually calling Value's default constructor.
// The rest of the implementation enforces that hasValue/value are
// synchronized.
///////////////////////////////////////////////////////////////////////////////
} // 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