template<class Func>
static auto handle(Func&& func) {
- static_assert(std::is_invocable_v<Func, ErrorT>);
return [
func = std::forward<Func>(func)
] (stateful_error_t<ErrorT>&& e) mutable -> decltype(auto) {
try {
std::rethrow_exception(e.ep);
} catch (const ErrorT& obj) {
- return std::invoke(std::forward<Func>(func), obj);
+ if constexpr (std::is_invocable_v<Func, decltype(obj)>) {
+ return std::invoke(std::forward<Func>(func), obj);
+ } else {
+ return std::invoke(std::forward<Func>(func));
+ }
}
ceph_abort_msg("exception type mismatch – impossible!");
};