Add full noexcept annotations to Indestructible
authorYedidya Feldblum <yfeldblum@fb.com>
Fri, 5 May 2017 06:43:22 +0000 (23:43 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 5 May 2017 06:51:23 +0000 (23:51 -0700)
Summary:
[Folly] Add full `noexcept` annotations to `Indestructible`.

And do it without requiring `<type_traits>`.

Reviewed By: Orvid

Differential Revision: D4999243

fbshipit-source-id: f3521237ef4d03d2b187e9ebd6d0c90887872c42

folly/Indestructible.h

index 285d9ed6a6d3529850de5ca31612aa5d3dcf9a36..ad1d21cbfeb3fcf06139215d385d69e6930fd64f 100644 (file)
@@ -17,7 +17,6 @@
 #pragma once
 
 #include <cassert>
-#include <type_traits>
 #include <utility>
 
 namespace folly {
@@ -64,7 +63,7 @@ class Indestructible final {
 
   template <typename... Args, typename = decltype(T(std::declval<Args&&>()...))>
   explicit constexpr Indestructible(Args&&... args) noexcept(
-      std::is_nothrow_constructible<T, Args&&...>::value)
+      noexcept(T(std::declval<Args&&>()...)))
       : storage_(std::forward<Args>(args)...) {}
 
   ~Indestructible() = default;
@@ -73,31 +72,31 @@ class Indestructible final {
   Indestructible& operator=(Indestructible const&) = delete;
 
   Indestructible(Indestructible&& other) noexcept(
-      std::is_nothrow_move_constructible<T>::value)
+      noexcept(T(std::declval<T&&>())))
       : storage_(std::move(other.storage_.value)) {
     other.erased_ = true;
   }
   Indestructible& operator=(Indestructible&& other) noexcept(
-      std::is_nothrow_move_assignable<T>::value) {
+      noexcept(T(std::declval<T&&>()))) {
     storage_.value = std::move(other.storage_.value);
     other.erased_ = true;
   }
 
-  T* get() {
+  T* get() noexcept {
     check();
     return &storage_.value;
   }
-  T const* get() const {
+  T const* get() const noexcept {
     check();
     return &storage_.value;
   }
-  T& operator*() { return *get(); }
-  T const& operator*() const { return *get(); }
-  T* operator->() { return get(); }
-  T const* operator->() const { return get(); }
+  T& operator*() noexcept { return *get(); }
+  T const& operator*() const noexcept { return *get(); }
+  T* operator->() noexcept { return get(); }
+  T const* operator->() const noexcept { return get(); }
 
  private:
-  void check() const {
+  void check() const noexcept {
     assert(!erased_);
   }
 
@@ -110,7 +109,8 @@ class Indestructible final {
     template <
         typename... Args,
         typename = decltype(T(std::declval<Args&&>()...))>
-    explicit constexpr Storage(Args&&... args)
+    explicit constexpr Storage(Args&&... args) noexcept(
+        noexcept(T(std::declval<Args&&>()...)))
         : value(std::forward<Args>(args)...) {}
 
     ~Storage() {}