Future::filter(A => bool)
[folly.git] / folly / ScopeGuard.h
index bb9ad86728857679a0e4616ddfc70501af8da209..64ddc60b462c851e16faac82079bea9c31e972b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
 #include <functional>
 #include <new>
 
-#include "folly/Preprocessor.h"
-#include "folly/detail/UncaughtExceptionCounter.h"
+#include <folly/Preprocessor.h>
+#include <folly/detail/UncaughtExceptionCounter.h>
 
 namespace folly {
 
@@ -77,7 +77,7 @@ class ScopeGuardImplBase {
   ScopeGuardImplBase()
     : dismissed_(false) {}
 
-  ScopeGuardImplBase(ScopeGuardImplBase&& other)
+  ScopeGuardImplBase(ScopeGuardImplBase&& other) noexcept
     : dismissed_(other.dismissed_) {
     other.dismissed_ = true;
   }
@@ -157,9 +157,9 @@ class ScopeGuardForNewException {
       , exceptionCounter_(std::move(other.exceptionCounter_)) {
   }
 
-  ~ScopeGuardForNewException() noexcept {
+  ~ScopeGuardForNewException() noexcept(executeOnException) {
     if (executeOnException == exceptionCounter_.isNewUncaughtException()) {
-      execute();
+      function_();
     }
   }
 
@@ -168,8 +168,6 @@ class ScopeGuardForNewException {
 
   void* operator new(size_t) = delete;
 
-  void execute() noexcept { function_(); }
-
   FunctionType function_;
   UncaughtExceptionCounter exceptionCounter_;
 };
@@ -219,17 +217,17 @@ operator+(detail::ScopeGuardOnExit, FunctionType&& fn) {
 
 #define SCOPE_EXIT \
   auto FB_ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE) \
-  = ::folly::detail::ScopeGuardOnExit() + [&]
+  = ::folly::detail::ScopeGuardOnExit() + [&]() noexcept
 
 #if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
     defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
 #define SCOPE_FAIL \
   auto FB_ANONYMOUS_VARIABLE(SCOPE_FAIL_STATE) \
-  = ::folly::detail::ScopeGuardOnFail() + [&]
+  = ::folly::detail::ScopeGuardOnFail() + [&]() noexcept
 
 #define SCOPE_SUCCESS \
   auto FB_ANONYMOUS_VARIABLE(SCOPE_SUCCESS_STATE) \
-  = ::folly::detail::ScopeGuardOnSuccess() + [&]
+  = ::folly::detail::ScopeGuardOnSuccess() + [&]()
 #endif // native uncaught_exception() supported
 
 #endif // FOLLY_SCOPEGUARD_H_