I'm writing some code that necessitates my caching an exception.
Please consider
int main() { std::exception_ptr ex; bool b = ex; } This doesn't compile due to ex not being convertible to a bool type. My current workaround is to write
bool b = !!ex; or even
bool b = ex ? true : false; The first way is ugly, the second one a tautology surely. I'm starting to blame the compiler (MSVC2015). Two things:
Is there a better way of checking if
exhas been set to an exception?(Related) Do I need to initialise
exin some way?
!!works, along with the conditional. What am I missing?bool b(ex);orbool b{ex};if you really want to store that result inbool.