There is an issue with boolean conversion. It allows syntaxes that are nearly always a pain.
There is, luckily, a solution: the Safe Bool idiom.
The problem with a conversion to bool
is that implicit conversion is dangerous.
std::auto_ptr<T> p = ..., q = ....;
if (p < q) // uh ?
Therefore, operator bool() const
is an abomination. Either you provide an explicit method... or you use the safe bool idiom.
The idea of the idiom is to give you an instance of a type with a pretty minimal subset of operations and almost no case where the implicit conversion will get you into trouble. This is done by using a pointer to member function.
Operations like if (p)
and if (!p)
then make sense, but if (p < q)
will fail to compile.
Read the link thoroughly for the complete solution, and you'll realize why it was a good idea not to have operator bool() const
.