Commit b229e1a5 authored by Michael Lee's avatar Michael Lee Committed by Facebook Github Bot

Switch to folly/Optional.h to use std::aligned_storage

Summary: Older versions of libc++ do not support `std::aligned_storage_t`, switch to something more widely supported.

Differential Revision: D5506449

fbshipit-source-id: 3f5cf5dddf00bda76d4f16cfd4d8944ee5f1ba55
parent f99fa528
...@@ -285,7 +285,8 @@ class Optional { ...@@ -285,7 +285,8 @@ class Optional {
struct StorageTriviallyDestructible { struct StorageTriviallyDestructible {
protected: protected:
bool hasValue_; bool hasValue_;
std::aligned_storage_t<sizeof(Value), alignof(Value)> value_[1]; typename std::aligned_storage<sizeof(Value), alignof(Value)>::type
value_[1];
public: public:
StorageTriviallyDestructible() : hasValue_{false} {} StorageTriviallyDestructible() : hasValue_{false} {}
...@@ -297,7 +298,8 @@ class Optional { ...@@ -297,7 +298,8 @@ class Optional {
struct StorageNonTriviallyDestructible { struct StorageNonTriviallyDestructible {
protected: protected:
bool hasValue_; bool hasValue_;
std::aligned_storage_t<sizeof(Value), alignof(Value)> value_[1]; typename std::aligned_storage<sizeof(Value), alignof(Value)>::type
value_[1];
public: public:
StorageNonTriviallyDestructible() : hasValue_{false} {} StorageNonTriviallyDestructible() : hasValue_{false} {}
...@@ -313,10 +315,10 @@ class Optional { ...@@ -313,10 +315,10 @@ class Optional {
} }
}; };
struct Storage : std::conditional_t< struct Storage : std::conditional<
std::is_trivially_destructible<Value>::value, std::is_trivially_destructible<Value>::value,
StorageTriviallyDestructible, StorageTriviallyDestructible,
StorageNonTriviallyDestructible> { StorageNonTriviallyDestructible>::type {
bool hasValue() const { bool hasValue() const {
return this->hasValue_; return this->hasValue_;
} }
...@@ -371,7 +373,7 @@ void swap(Optional<T>& a, Optional<T>& b) { ...@@ -371,7 +373,7 @@ void swap(Optional<T>& a, Optional<T>& b) {
} }
} }
template <class T, class Opt = Optional<std::decay_t<T>>> template <class T, class Opt = Optional<typename std::decay<T>::type>>
Opt make_optional(T&& v) { Opt make_optional(T&& v) {
return Opt(std::forward<T>(v)); return Opt(std::forward<T>(v));
} }
...@@ -471,7 +473,7 @@ struct hash<folly::Optional<T>> { ...@@ -471,7 +473,7 @@ struct hash<folly::Optional<T>> {
if (!obj.hasValue()) { if (!obj.hasValue()) {
return 0; return 0;
} }
return hash<remove_const_t<T>>()(*obj); return hash<typename remove_const<T>::type>()(*obj);
} }
}; };
FOLLY_NAMESPACE_STD_END FOLLY_NAMESPACE_STD_END
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment