folly::fibers::Baton API consistency with folly::Baton
[folly.git] / folly / Replaceable.h
index 3021ed245d53f931d61d660dd2b640be82f99bc0..92d1ec6f6bc3d6402642bbc718dc833467c9a00a 100644 (file)
 #include <type_traits>
 #include <utility>
 
-#include <folly/Launder.h>
+#include <folly/Portability.h>
 #include <folly/Traits.h>
 #include <folly/Utility.h>
+#include <folly/lang/Launder.h>
 
 /**
  * An instance of `Replaceable<T>` wraps an instance of `T`.
@@ -307,7 +308,8 @@ struct copy_ctor_mixin<T, true> {
   copy_ctor_mixin() = default;
   inline copy_ctor_mixin(copy_ctor_mixin const& other) noexcept(
       std::is_nothrow_constructible<T, T const&>::value) {
-    ::new (reinterpret_cast<Replaceable<T>*>(this)->storage_) T(*other);
+    ::new (reinterpret_cast<Replaceable<T>*>(this)->storage_)
+        T(*reinterpret_cast<Replaceable<T> const&>(other));
   }
   copy_ctor_mixin(copy_ctor_mixin&&) = default;
   copy_ctor_mixin& operator=(copy_ctor_mixin&&) = default;
@@ -356,10 +358,6 @@ struct is_constructible_from_replaceable
               std::is_constructible<T, const Replaceable<T>&>::value ||
               std::is_constructible<T, const Replaceable<T>&&>::value> {};
 
-template <typename T>
-constexpr bool is_constructible_from_replaceable_v{
-    is_constructible_from_replaceable<T>::value};
-
 template <typename T>
 struct is_convertible_from_replaceable
     : std::integral_constant<
@@ -368,10 +366,6 @@ struct is_convertible_from_replaceable
               std::is_convertible<Replaceable<T>&&, T>::value ||
               std::is_convertible<const Replaceable<T>&, T>::value ||
               std::is_convertible<const Replaceable<T>&&, T>::value> {};
-
-template <typename T>
-constexpr bool is_convertible_from_replaceable_v{
-    is_convertible_from_replaceable<T>::value};
 } // namespace replaceable_detail
 
 // Type trait template to statically test whether a type is a specialization of
@@ -382,9 +376,6 @@ struct is_replaceable : std::false_type {};
 template <class T>
 struct is_replaceable<Replaceable<T>> : std::true_type {};
 
-template <class T>
-constexpr bool is_replaceable_v{is_replaceable<T>::value};
-
 // Function to make a Replaceable with a type deduced from its input
 template <class T>
 constexpr Replaceable<std::decay_t<T>> make_replaceable(T&& t) {
@@ -460,7 +451,7 @@ class alignas(T) Replaceable
   template <
       class... Args,
       std::enable_if_t<std::is_constructible<T, Args&&...>::value, int> = 0>
-  constexpr explicit Replaceable(in_place_t, Args&&... args)
+  FOLLY_CPP14_CONSTEXPR explicit Replaceable(in_place_t, Args&&... args)
       // clang-format off
       noexcept(std::is_nothrow_constructible<T, Args&&...>::value)
       // clang-format on
@@ -474,7 +465,7 @@ class alignas(T) Replaceable
       std::enable_if_t<
           std::is_constructible<T, std::initializer_list<U>, Args&&...>::value,
           int> = 0>
-  constexpr explicit Replaceable(
+  FOLLY_CPP14_CONSTEXPR explicit Replaceable(
       in_place_t,
       std::initializer_list<U> il,
       Args&&... args)
@@ -496,7 +487,7 @@ class alignas(T) Replaceable
               !std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
               std::is_convertible<U&&, T>::value,
           int> = 0>
-  constexpr /* implicit */ Replaceable(U&& other)
+  FOLLY_CPP14_CONSTEXPR /* implicit */ Replaceable(U&& other)
       // clang-format off
       noexcept(std::is_nothrow_constructible<T, U&&>::value)
       // clang-format on
@@ -512,7 +503,7 @@ class alignas(T) Replaceable
               !std::is_same<Replaceable<T>, std::decay_t<U>>::value &&
               !std::is_convertible<U&&, T>::value,
           int> = 0>
-  explicit constexpr Replaceable(U&& other)
+  FOLLY_CPP14_CONSTEXPR explicit Replaceable(U&& other)
       // clang-format off
       noexcept(std::is_nothrow_constructible<T, U&&>::value)
       // clang-format on
@@ -524,8 +515,9 @@ class alignas(T) Replaceable
       class U,
       std::enable_if_t<
           std::is_constructible<T, const U&>::value &&
-              !replaceable_detail::is_constructible_from_replaceable_v<T> &&
-              !replaceable_detail::is_convertible_from_replaceable_v<T> &&
+              !replaceable_detail::is_constructible_from_replaceable<
+                  T>::value &&
+              !replaceable_detail::is_convertible_from_replaceable<T>::value &&
               std::is_convertible<const U&, T>::value,
           int> = 0>
   /* implicit */ Replaceable(const Replaceable<U>& other)
@@ -540,8 +532,9 @@ class alignas(T) Replaceable
       class U,
       std::enable_if_t<
           std::is_constructible<T, const U&>::value &&
-              !replaceable_detail::is_constructible_from_replaceable_v<T> &&
-              !replaceable_detail::is_convertible_from_replaceable_v<T> &&
+              !replaceable_detail::is_constructible_from_replaceable<
+                  T>::value &&
+              !replaceable_detail::is_convertible_from_replaceable<T>::value &&
               !std::is_convertible<const U&, T>::value,
           int> = 0>
   explicit Replaceable(const Replaceable<U>& other)
@@ -556,8 +549,9 @@ class alignas(T) Replaceable
       class U,
       std::enable_if_t<
           std::is_constructible<T, U&&>::value &&
-              !replaceable_detail::is_constructible_from_replaceable_v<T> &&
-              !replaceable_detail::is_convertible_from_replaceable_v<T> &&
+              !replaceable_detail::is_constructible_from_replaceable<
+                  T>::value &&
+              !replaceable_detail::is_convertible_from_replaceable<T>::value &&
               std::is_convertible<U&&, T>::value,
           int> = 0>
   /* implicit */ Replaceable(Replaceable<U>&& other)
@@ -572,8 +566,9 @@ class alignas(T) Replaceable
       class U,
       std::enable_if_t<
           std::is_constructible<T, U&&>::value &&
-              !replaceable_detail::is_constructible_from_replaceable_v<T> &&
-              !replaceable_detail::is_convertible_from_replaceable_v<T> &&
+              !replaceable_detail::is_constructible_from_replaceable<
+                  T>::value &&
+              !replaceable_detail::is_convertible_from_replaceable<T>::value &&
               !std::is_convertible<U&&, T>::value,
           int> = 0>
   explicit Replaceable(Replaceable<U>&& other)
@@ -628,7 +623,7 @@ class alignas(T) Replaceable
     return launder(reinterpret_cast<T const*>(storage_));
   }
 
-  constexpr T* operator->() {
+  FOLLY_CPP14_CONSTEXPR T* operator->() {
     return launder(reinterpret_cast<T*>(storage_));
   }
 
@@ -636,11 +631,11 @@ class alignas(T) Replaceable
     return *launder(reinterpret_cast<T const*>(storage_));
   }
 
-  constexpr T& operator*() & {
+  FOLLY_CPP14_CONSTEXPR T& operator*() & {
     return *launder(reinterpret_cast<T*>(storage_));
   }
 
-  constexpr T&& operator*() && {
+  FOLLY_CPP14_CONSTEXPR T&& operator*() && {
     return std::move(*launder(reinterpret_cast<T*>(storage_)));
   }