My class has an explicit conversion to bool:
struct T {
explicit operator bool() const { return true; }
};
and I have an instance of it:
T t;
To assign it to a variable of type bool
, I need to write a cast:
bool b = static_cast<bool>(t);
bool b = bool(t);
bool b(t); // converting initialiser
bool b{static_cast<bool>(t)};
I know that I can use my type directly in a conditional without a cast, despite the explicit
qualifier:
if (t)
/* statement */;
Where else can I use t
as a bool
without a cast?