----- Original Message ----- From: "Reece Dunn" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, May 27, 2003 1:57 PM Subject: Re: [boost] Re: Enum operators
> I have adopted a Java-style approach to enumerated-style values (don't know > if this is the best approach, just the way that I do it now). For example: > > class WhatIsTheMatrix > { > public: > typedef unsigned char type; > public: > static const type TheWhat = 0; > static const type Matrix = 1; > static const type AniMatrix = 2; > static const type MatrixReloaded = 3; > static const type MatrixRevolutions = 4; > }; I think this is really cool! Basically, you should be able to do WhatIsTheMatrix::type m = WhatIsTheMatrix::TheWhat; ++m; switch( m) { case WhatIsTheMatrix::TheWhat: //... case WhatIsTheMatrix::AniMatrix: //... ... } The unfortunate thing is that you lose compile-time checking. You'll be able to say something like WhatIsTheMatrix::type m = 20; What I would really love is some library to allow me to do something similar to this: ENUM(Variant) { VT_I1, VT_I2, VT_I4, VT_BSTR, BIT_FLAGS( VT_BYREF, VT_ARRAY) }; Here's how it should roughly behave: Variant a = VT_I1; // ok Variant b = VT_I1 | VT_BSTR; // error Variant c = VT_I1 | VT_I4; // error Variant d = VT_I1 | VT_ARRAY; // ok - using with bitflag Variant e = VT_BSTR | VT_ARRAY | VT_BYREF; // ok - using with bitflags I'm not sure operators like ++,--, +,-, etc. should be made workable for enums. If you actually want that, use ints. Just think about something like this: Day a = Thursday; Day b = Wednesday; Day c = a + b; (note: I once created a library that for a given enumerator that could contain bit-flags, allowed showing its user-friendly string in debug mode - like, for e, it would be "VT_BSTR | VT_ARRAY | VT_BYREF") Best, John > > It could be possible to use the suggestions for enumerated type traits to > support this form and convert the class into its own data type, so you could > use it like: > > WhatIsTheMatrix witm(); // initialized to WhatIsTheMatrix::TheWhat > WhatIsTheMatrix neo( WhatIsTheMatrix::MatrixReloaded ); > > if( witm == neo ) ...; > else ...; > > -- just an idea. > > Regards, > Reece > > _________________________________________________________________ > Stay in touch with absent friends - get MSN Messenger > http://www.msn.co.uk/messenger > > _______________________________________________ > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost > _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost