[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: macro for enum operations
From: Lubos Lunak <l.lunak () suse ! cz>
Date: 2003-09-10 11:15:12
[Download RAW message or body]
On Wednesday 10 of September 2003 12:32, Simon Hausmann wrote:
> Hi,
>
> seeing that KFileDialog::setMode( KFile::Mode ) is deprecated in favour of
> KFileDialog::setMode( int ) makes me wonder about adding a a macro to
> kdecore/kdemacros.h that does that nifty trick of defining operations for
> combining enum values to get a nicer API but keep type safety (like we've
> see in the Qt4 presentation in n7y) :
>
> #define K_DEFINE_ENUM_OPERATIONS( EnumType ) \
> inline EnumType operator^( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); } \
> inline EnumType operator&( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); } \
> inline EnumType operator|( EnumType first, EnumType second ) \
> { return EnumType( int( first ) ^ int( second ) ); }
>
>
> Then we could mark the KFileDialog::setMode( int ) method deprecated :)
>
> Thoughts/Opinions?
s/int/unsigned long/ , I'd say
Looks like a good idea, even though creating enum values that are not defined
in the enum feels a bit scary, as enum is usually seen as 'one value from a
set', but that's probably just because I'm not used to them this way.
--
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o. e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27 tel: +420 2 9654 2373
190 00 Praha 9 fax: +420 2 9654 2374
Czech Republic http://www.suse.cz/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic