From 653053aa7a270129b35d405e3d196210c44ec6e2 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Wed, 10 Jan 2018 17:52:16 -0800 Subject: [PATCH 1/1] Cut the ScopeGuard alias now that we have auto Summary: [Folly] Cut the `ScopeGuard` alias now that we have `auto`. This form works because of hidden lifetime extension: ```lang=c++ folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ }); // ... // guard falls out of scope ``` But this form would not work correctly: ```lang=c++ folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ }); std::async(std::launch::async, [guard = std::move(guard)] {}); ``` Because `folly::ScopeGuard` is an rvalue-reference-to-base. We have `auto`, so just remove `folly::ScopeGuard`. This form works correctly: ```lang=c++ auto guard = folly::makeGuard([] { /*...*/ }); std::async(std::launch::async, [guard = std::move(guard)] {}); ``` Reviewed By: igorsugak Differential Revision: D6690070 fbshipit-source-id: 54e32b300d36fce4eb95a59f1828819afe312ec0 --- folly/ScopeGuard.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/folly/ScopeGuard.h b/folly/ScopeGuard.h index 135d2c4c..410dc6f7 100644 --- a/folly/ScopeGuard.h +++ b/folly/ScopeGuard.h @@ -185,11 +185,6 @@ detail::ScopeGuardImplDecay makeGuard(F&& f) noexcept( return detail::ScopeGuardImplDecay(static_cast(f)); } -/** - * This is largely unneeded if you just use auto for your guards. - */ -typedef detail::ScopeGuardImplBase&& ScopeGuard; - namespace detail { #if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \ -- 2.34.1