2013/3/14 John Maddock
Just discovered (oops!) that the so called safe bool ideom is not as safe as it appears, for example:
class Testable { bool ok_; typedef void (Testable::*bool_type)() const; void this_type_does_not_support_**comparisons() const {} public: explicit Testable(bool b=true):ok_(b) {}
operator bool_type() const { return ok_==true ? &Testable::this_type_does_not_**support_comparisons : 0; } };
Testable t(true);
bool b = t; // Compiles OK - Ooops!
I'm curious, why is this bad? I personally hate the fact, that the above doesn't compile for explicit operator bool(), which leads to idioms like !!t. Regards, Kris Which is causing multiprecision to misbehave when used in conjunction with
uBlas: https://svn.boost.org/trac/**boost/ticket/8292#comment:2https://svn.boost.org/trac/boost/ticket/8292#comment:2
I guess making the conversion explicit in C++11 mode would help (I still need to test that), but is there a C++03 solution?
Thanks, John.