RFC: bool operators for some classes
Guillaume Laurent
glaurent at telegraph-road.org
Fri Jan 3 09:00:54 GMT 2003
On Friday 03 January 2003 02:04, Malte Starostik wrote:
> which ain't only shorter but also scopes those variables more
> appropriately.
And most of all is much less readable (IMHO).
> operator const void* () const { return isValid() ? this : 0; }
As an intensive user of the Qt and KDE API, this is typically the kind of
thing I'd really really *NOT* like to have. It's not intuitive, because the
condition on which you base the boolean conversion will be very diverse all
throughout the various classes, and I'd wage that in many cases the choice of
that condition will be ambiguous. David cited QString, which has both
isNull() and isEmpty() : which one would you use for a bool conversion ?
Likewise, KURL also has isValid() and isEmpty()...
The only case where I'd agree with having the operator are KSaveFile and
KTempFile, because it's consistent with the std streams API
while (file) { ... }
--
Guillaume
http://www.telegraph-road.org
More information about the kde-core-devel
mailing list