I'm writing a script type like std::optional<T>
. I've seen the document saying that the bool opImplConv()
won't be used because of ambiguity. But I think it can use bool opConv()
to convert the result of expression to bool
. The if
statement itself is enough to consider the user needs a explicit conversion. This is exactly how C++ deal with non-bool
result in a if condition, it will invoke the operator bool()
of that type even if it is declared as explicit operator bool()
.
If this feature can be implemented, I can write script like this
optional<string> opt_str = "test";
if(opt_str)
// ...
instead of
optional<string> opt_str = "test";
if(bool(opt_str))
// ...