Commit 6cd060f1 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

move return type calculation in catch_exception

Summary: Ideal for dependent return types to be calculated in the template param list rather since the putting them in the leading or trailing return type slot makes the function name opaque to demangling.

Reviewed By: Orvid

Differential Revision: D28140885

fbshipit-source-id: 0f9bc182f12a6383205863ce9a79b01961d644a6
parent 0f30fbc4
......@@ -24,6 +24,7 @@
#include <folly/CppAttributes.h>
#include <folly/Portability.h>
#include <folly/Traits.h>
#include <folly/Utility.h>
#include <folly/lang/TypeInfo.h>
namespace folly {
......@@ -145,18 +146,20 @@ template <
typename F,
typename... A,
typename FD = std::remove_pointer_t<std::decay_t<F>>,
std::enable_if_t<!std::is_function<FD>::value, int> = 0>
FOLLY_NOINLINE FOLLY_COLD auto invoke_cold(F&& f, A&&... a)
-> decltype(static_cast<F&&>(f)(static_cast<A&&>(a)...)) {
std::enable_if_t<!std::is_function<FD>::value, int> = 0,
typename R = decltype(FOLLY_DECLVAL(F &&)(FOLLY_DECLVAL(A &&)...))>
FOLLY_NOINLINE FOLLY_COLD R invoke_cold(F&& f, A&&... a) //
noexcept(noexcept(static_cast<F&&>(f)(static_cast<A&&>(a)...))) {
return static_cast<F&&>(f)(static_cast<A&&>(a)...);
}
template <
typename F,
typename... A,
typename FD = std::remove_pointer_t<std::decay_t<F>>,
std::enable_if_t<std::is_function<FD>::value, int> = 0>
FOLLY_ERASE auto invoke_cold(F&& f, A&&... a)
-> decltype(f(static_cast<A&&>(a)...)) {
std::enable_if_t<std::is_function<FD>::value, int> = 0,
typename R = decltype(FOLLY_DECLVAL(F &&)(FOLLY_DECLVAL(A &&)...))>
FOLLY_ERASE R invoke_cold(F&& f, A&&... a) //
noexcept(noexcept(f(static_cast<A&&>(a)...))) {
return f(static_cast<A&&>(a)...);
}
......@@ -219,12 +222,16 @@ template <typename F, typename... A>
/// [](auto&& e, int num) { return num; },
/// def);
/// assert(result == input < 0 ? def : input);
template <typename E, typename Try, typename Catch, typename... CatchA>
FOLLY_ERASE_TRYCATCH auto catch_exception(Try&& t, Catch&& c, CatchA&&... a) ->
typename std::common_type<
decltype(static_cast<Try&&>(t)()),
decltype(static_cast<Catch&&>(c)(
std::declval<E>(), static_cast<CatchA&&>(a)...))>::type {
template <
typename E,
typename Try,
typename Catch,
typename... CatchA,
typename R = std::common_type_t<
decltype(FOLLY_DECLVAL(Try &&)()),
decltype(FOLLY_DECLVAL(Catch &&)(
FOLLY_DECLVAL(E&), FOLLY_DECLVAL(CatchA&&)...))>>
FOLLY_ERASE_TRYCATCH R catch_exception(Try&& t, Catch&& c, CatchA&&... a) {
#if FOLLY_HAS_EXCEPTIONS
try {
return static_cast<Try&&>(t)();
......@@ -259,11 +266,14 @@ FOLLY_ERASE_TRYCATCH auto catch_exception(Try&& t, Catch&& c, CatchA&&... a) ->
/// [](int num) { return num; },
/// def);
/// assert(result == input < 0 ? def : input);
template <typename Try, typename Catch, typename... CatchA>
FOLLY_ERASE_TRYCATCH auto catch_exception(Try&& t, Catch&& c, CatchA&&... a) ->
typename std::common_type<
decltype(static_cast<Try&&>(t)()),
decltype(static_cast<Catch&&>(c)(static_cast<CatchA&&>(a)...))>::type {
template <
typename Try,
typename Catch,
typename... CatchA,
typename R = std::common_type_t<
decltype(FOLLY_DECLVAL(Try &&)()),
decltype(FOLLY_DECLVAL(Catch &&)(FOLLY_DECLVAL(CatchA &&)...))>>
FOLLY_ERASE_TRYCATCH R catch_exception(Try&& t, Catch&& c, CatchA&&... a) {
#if FOLLY_HAS_EXCEPTIONS
try {
return static_cast<Try&&>(t)();
......
......@@ -18,6 +18,7 @@
#include <algorithm>
#include <cstring>
#include <functional>
#include <string>
#include <folly/Portability.h>
......@@ -42,6 +43,17 @@ extern "C" FOLLY_KEEP std::exception const* check_get_object_exception(
return folly::exception_ptr_get_object<std::exception>(ptr);
}
extern "C" FOLLY_KEEP void check_cond_catch_exception(bool c) {
auto try_ = [=] { c ? folly::throw_exception(0) : void(); };
auto catch_ = folly::detail::keep_sink<>;
folly::catch_exception(try_, std::bind(catch_));
}
extern "C" FOLLY_KEEP void check_cond_catch_exception_ptr(bool c) {
auto try_ = [=] { c ? folly::throw_exception(0) : void(); };
auto catch_ = folly::detail::keep_sink<>;
folly::catch_exception(try_, catch_);
}
template <typename Ex>
static std::string message_for_terminate_with(std::string const& what) {
auto const name = folly::pretty_name<Ex>();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment