template<class T>
class evo::SafeBool< T >
Safe bool base class.
This implements "safe" boolean evaluation, without the side-effects of implicit conversions from the bool type.
- Use by deriving the intended class from SafeBool
- The deriving class must implement the logical negation operator (as const) for boolean evaluation
- Safe bool comparisons (
obj1
==
obj2
or obj1
!=
obj1
) will not compile unless the deriving class implements operator==() or operator!=(), respectively
- No virtual methods are used even though this is a base class
- Template Parameters
-
T | The deriving type being used. |
- Example:
bool operator!() const
{ return false; }
};
void func() {
const Foo foo;
if (foo) {
}
if (!foo) {
}
}