+
+private:
+ // What makes this useful is that T can be exception_wrapper* or
+ // const exception_wrapper*, and the compiler will use the
+ // instantiation which works with F.
+ template <class Ex, class F, class T>
+ static bool with_exception1(F f, T* that) {
+ if (that->item_) {
+ if (auto ex = dynamic_cast<Ex*>(that->getCopied())) {
+ f(*ex);
+ return true;
+ }
+ } else if (that->eptr_) {
+ try {
+ std::rethrow_exception(that->eptr_);
+ } catch (std::exception& e) {
+ if (auto ex = dynamic_cast<Ex*>(&e)) {
+ f(*ex);
+ return true;
+ }
+ } catch (...) {
+ // fall through
+ }
+ }
+ return false;
+ }