27-11-2025, 09:04 AM
Rule 7.0.2 has exceptions for "a class type having an explicit operator bool."
Question: why does the conversion operator have to be 'explicit' for the exception to apply? Even if the conversion operator is implicit, clearly the class was designed to be convertible to bool. This requirement seems therefore excessive.
I'm thinking for example about std::bitset::operator[] which returns a proxy object convertible to bool. However since the conversion operator is not explicit (as specified in the C++ standard), then even performing an explicit cast to bool from the proxy object violates Rule 7.0.2.
Note: I am aware that the 'const' version of std::bitset::operator[] should return a 'bool' directly, but some implementations return the proxy object also here, so the conversion is still necessary.
Question: why does the conversion operator have to be 'explicit' for the exception to apply? Even if the conversion operator is implicit, clearly the class was designed to be convertible to bool. This requirement seems therefore excessive.
I'm thinking for example about std::bitset::operator[] which returns a proxy object convertible to bool. However since the conversion operator is not explicit (as specified in the C++ standard), then even performing an explicit cast to bool from the proxy object violates Rule 7.0.2.
Note: I am aware that the 'const' version of std::bitset::operator[] should return a 'bool' directly, but some implementations return the proxy object also here, so the conversion is still necessary.

