From 15e17fa26d26cc486827824c9d945e1344622732 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Mon, 30 Nov 2015 22:54:20 -0800 Subject: [PATCH] CodeMod: Use the ExceptionWrapper::with_exception variant that deduces exception types Summary: CodeMod: Use the `ExceptionWrapper::with_exception` variant that deduces exception types. Since we must specify the exception type in the lambda arg, and there is a variant of `ExceptionWrapper::with_exception` that deduces the type of the exception from the type of the lambda arg, we don't need to specify the exception type again as a template parameter anymore. Reviewed By: meyering Differential Revision: D2694895 fb-gh-sync-id: 505469f9008973a315e836f356e5db97df4ec921 --- folly/ExceptionWrapper.h | 4 ++-- folly/futures/Try.h | 4 ++-- folly/test/ExceptionWrapperTest.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/folly/ExceptionWrapper.h b/folly/ExceptionWrapper.h index f97f1a8e..7a5610b7 100644 --- a/folly/ExceptionWrapper.h +++ b/folly/ExceptionWrapper.h @@ -89,11 +89,11 @@ namespace folly { * // Thread2: Exceptions are bad! * void processResult() { * auto ep = globalExceptionWrapper.get(); - * if (!ep.with_exception([&]( + * if (!ep.with_exception([&]( * FacePlantException& faceplant) { * LOG(ERROR) << "FACEPLANT"; * })) { - * ep.with_exception([&]( + * ep.with_exception([&]( * FailWhaleException& failwhale) { * LOG(ERROR) << "FAILWHALE!"; * }); diff --git a/folly/futures/Try.h b/folly/futures/Try.h index beec20a2..4aeea8fc 100644 --- a/folly/futures/Try.h +++ b/folly/futures/Try.h @@ -209,7 +209,7 @@ class Try { if (!hasException()) { return false; } - return e_->with_exception(std::move(func)); + return e_->with_exception(std::move(func)); } template @@ -329,7 +329,7 @@ class Try { if (!hasException()) { return false; } - return e_->with_exception(std::move(func)); + return e_->with_exception(std::move(func)); } template diff --git a/folly/test/ExceptionWrapperTest.cpp b/folly/test/ExceptionWrapperTest.cpp index 265c5b02..74e2d0d3 100644 --- a/folly/test/ExceptionWrapperTest.cpp +++ b/folly/test/ExceptionWrapperTest.cpp @@ -162,7 +162,7 @@ TEST(ExceptionWrapper, with_exception_test) { EXPECT_TRUE(bool(ew)); EXPECT_EQ(ew.what(), "IntException: int == 23"); EXPECT_EQ(ew.class_name(), "IntException"); - ew.with_exception([&](const IntException& ie) { + ew.with_exception([&](const IntException& ie) { EXPECT_EQ(ie.getInt(), expected); }); @@ -175,7 +175,7 @@ TEST(ExceptionWrapper, with_exception_test) { EXPECT_TRUE(bool(ew2)); EXPECT_EQ(ew2.what(), "IntException: int == 23"); EXPECT_EQ(ew2.class_name(), "IntException"); - ew2.with_exception([&](AbstractIntException& ie) { + ew2.with_exception([&](AbstractIntException& ie) { EXPECT_EQ(ie.getInt(), expected); #if __CLANG_PREREQ(3, 6) # pragma clang diagnostic push @@ -190,14 +190,14 @@ TEST(ExceptionWrapper, with_exception_test) { // Test with const this. If this compiles and does not crash due to // infinite loop when it runs, it succeeds. const exception_wrapper& cew = ew; - cew.with_exception([&](const IntException& ie) { + cew.with_exception([&](const IntException& ie) { SUCCEED(); }); // This won't even compile. You can't use a function which takes a // non-const reference with a const exception_wrapper. /* - cew.with_exception([&](IntException& ie) { + cew.with_exception([&](IntException& ie) { SUCCEED(); }); */ -- 2.34.1