RFC: bool operators for some classes

Malte Starostik malte at kde.org
Fri Jan 3 02:30:02 GMT 2003


On Friday 03 January 2003 02:49, Carsten Pfeiffer wrote:
> On Friday 03 January 2003 02:04, Malte Starostik wrote:
> > If those classes provided a boolean conversion, the above could be
> > written more tersely:
> >
> > if ( KFileMetaInfoItem artist = metaInfo.item( KFileMimeTypeInfo::Author
> > ) )
>
> [...]
>
> > which ain't only shorter but also scopes those variables more
> > appropriately. So I'd like to suggest the addition of
>
> I for one don't like boolean operators on classes very much because they're
> not intuitive to use or understand (what if a KFileMetaInfo object is NOT?
> :)
>
> What's wrong with
> if ( (KFileMetaInfoItem artist =
>       metaInfo.item( KFileMimeTypeInfo::Author ) ).isValid() )

It's a syntax error. Declaration inside the condition of an if-statement only 
works if the declared object is also initialized (satisfied above) and 
convertible to bool (not satisfied above). It cannot be used as part of 
another expression that might be convertible to bool as above :-(

-Malte




More information about the kde-core-devel mailing list