I agree, enum variable should only contain one of the
enumerated values. Here's an example how current way may lead
to unexpected result:
enum Foo { A = 1, B }
void bar( Foo foo ) {
final switch( foo ) {
case Foo.A:
writeln( A );
return;
case Foo.B:
Trass3r:
As I said one could introduce something like @flags but I guess a
library solution is preferred.
I still wonder though if implicit conversion to the basetype has
any merit.
Those are important topics. D must offer a solution that is both safer and more
handy than the current one.
On Thursday, 26 January 2012 at 01:44:23 UTC, Marco Leise wrote:
Delphi:
http://delphi.about.com/od/beginners/a/delphi_set_type.htm |
Scroll to: Sets with Enumerations
Sets use the smallest integer type that can hold enough bits
for the number of elements in an enum. So up to 8 enum flags
use
On Thu, 26 Jan 2012 00:49:58 +0100, Trass3r u...@known.com wrote:
In the codebase I have to work with, having the same enum specified in
different places is rather common. Yeah, I hate it. This means I might
have a filter defined using one enum, and the value to filter being a
different type
On Wed, 25 Jan 2012 03:22:03 +0100, Trass3r u...@known.com wrote:
Does it really make sense to allow bitwise operations on different enums?
Maybe. Certainly sometimes, but those could just as easily use casts.
There should at least be some way to get this straight without having to
resort
So I was just reading
http://stackoverflow.com/questions/1448396/how-to-use-enums-as-flags-in-c
And did a quick test:
enum STC
{
A = 0x1,
B = 0x2,
C = 0x4
}
enum FOO
{
F = 0x8,
G = 0x10
}
void main()
{
STC s = STC.A | STC.C;
STC s2 = s
On Wed, 25 Jan 2012 03:22:03 +0100, Trass3r u...@known.com
wrote:
Does it really make sense to allow bitwise operations
on different enums?
Maybe. Certainly sometimes, but those could just as easily
use casts.
There should at least be some way to get this straight
without having to
Does it really make sense to allow bitwise operations on different
enums?
Maybe. Certainly sometimes
Examples please.
but those could just as easily use casts.
Seconded.
I generally don't see any merit in letting enums *implicitly* convert to
their base type.
On Wed, 25 Jan 2012 22:47:49 +0100, Trass3r u...@known.com wrote:
Does it really make sense to allow bitwise operations on different
enums?
Maybe. Certainly sometimes
Examples please.
In the codebase I have to work with, having the same enum specified in
different places is rather common.
In the codebase I have to work with, having the same enum specified in
different places is rather common. Yeah, I hate it. This means I might
have a filter defined using one enum, and the value to filter being a
different type with the same values.
Why don't you fix it then?
On Wednesday, January 25, 2012 03:22:03 Trass3r wrote:
So I was just reading
http://stackoverflow.com/questions/1448396/how-to-use-enums-as-flags-in-c
And did a quick test:
enum STC
{
A = 0x1,
B = 0x2,
C = 0x4
}
enum FOO
{
F = 0x8,
G = 0x10
}
void
I think that it makes sense to use enums as flags, but I do _not_ think
that it makes sense to use an enum as the type of the variable _holding_
the flags.
STC var = STC.A STC.B;
We could easily introduce @flags enum or whatever to make it more clear
like in C#.
just makes it worse.
On Wednesday, January 25, 2012 03:22:03 Trass3r wrote:
So I was just reading
http://stackoverflow.com/questions/1448396/how-to-use-enums-as-flags-in-c
And did a quick test:
I think that it makes sense to use enums as flags, but I do
_not_ think that it
makes sense to use an enum as
On Thursday, January 26, 2012 01:17:51 Trass3r wrote:
I think that it makes sense to use enums as flags, but I do _not_ think
that it makes sense to use an enum as the type of the variable _holding_
the flags.
STC var = STC.A STC.B;
We could easily introduce @flags enum or whatever
26.01.2012 2:40, Jonathan M Davis пишет:
What type safety? You're dealing with a uint (or ushort or ulong) with a bunch
of specific bits set which represent flags. What other type would you want? You
could typedef it I suppose (well, use the TypeDef library type when it's
merged in anyway), but
Delphi: http://delphi.about.com/od/beginners/a/delphi_set_type.htm |
Scroll to: Sets with Enumerations
Sets use the smallest integer type that can hold enough bits for the
number of elements in an enum. So up to 8 enum flags use a byte for
example. TDaySet in the example code would also be 1
16 matches
Mail list logo