Switch to folly/Optional.h to use std::aligned_storage
authorMichael Lee <mzlee@fb.com>
Thu, 27 Jul 2017 16:20:04 +0000 (09:20 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 27 Jul 2017 16:34:31 +0000 (09:34 -0700)
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

folly/Optional.h

index cdf05201e163cb0dacb5b0b4e5a29f762dbf3b9c..f8d39cb8cc39e0ce9b4407041e5a9d329be7e825 100644 (file)
@@ -285,7 +285,8 @@ class Optional {
   struct StorageTriviallyDestructible {
    protected:
     bool hasValue_;
-    std::aligned_storage_t<sizeof(Value), alignof(Value)> value_[1];
+    typename std::aligned_storage<sizeof(Value), alignof(Value)>::type
+        value_[1];
 
    public:
     StorageTriviallyDestructible() : hasValue_{false} {}
@@ -297,7 +298,8 @@ class Optional {
   struct StorageNonTriviallyDestructible {
    protected:
     bool hasValue_;
-    std::aligned_storage_t<sizeof(Value), alignof(Value)> value_[1];
+    typename std::aligned_storage<sizeof(Value), alignof(Value)>::type
+        value_[1];
 
    public:
     StorageNonTriviallyDestructible() : hasValue_{false} {}
@@ -313,10 +315,10 @@ class Optional {
     }
   };
 
-  struct Storage : std::conditional_t<
+  struct Storage : std::conditional<
                        std::is_trivially_destructible<Value>::value,
                        StorageTriviallyDestructible,
-                       StorageNonTriviallyDestructible> {
+                       StorageNonTriviallyDestructible>::type {
     bool hasValue() const {
       return this->hasValue_;
     }
@@ -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) {
   return Opt(std::forward<T>(v));
 }
@@ -471,7 +473,7 @@ struct hash<folly::Optional<T>> {
     if (!obj.hasValue()) {
       return 0;
     }
-    return hash<remove_const_t<T>>()(*obj);
+    return hash<typename remove_const<T>::type>()(*obj);
   }
 };
 FOLLY_NAMESPACE_STD_END