-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 7358 - final switch over enum should add throwing default in debug mode #673
Conversation
|
This is good. We must discuss disabling "|" for enums (which I think is terrible) separately. |
|
@andralex I think disabling that would be very unreasonable; it would make using enums for sort-of-type-safe bit flags annoying. |
|
@alexrp ... and would make using enums for REALLY GOOD CATEGORICAL TYPES awesome. |
|
Possibly you could make a case for bitwise operations on enums which have had their size explicitly specified and all members given explicit values (eg, enum Foo : int { A = 1, B = 2 }, the Windows header files use enums in that way), but I don't think there's any case for allowing bitwise operations on enums which haven't explicitly specified a type. |
|
@andralex: and would make porting C/C++ code difficult. |
|
|
|
@jmdavis: It would be great if we could actually define valid operations on enums. For example if you want to only define enum Flag
{
a = 0x01,
b = 0x02;
@disable auto opBinary(string op, T)(T rhs) { }
auto opBinary(string op : "|", T)(T rhs) { return this | rhs; }
}Which would be similar to: struct Flag
{
int flag;
enum a = 0x01;
enum b = 0x02;
@disable auto opBinary(string op, T)(T rhs) { }
auto opBinary(string op : "|", T)(T rhs) { return Flag(this.flag | rhs.flag); }
}
void main()
{
Flag f = Flag(Flag.a) | Flag(Flag.b);
assert(f.flag == (0x01 | 0x02));
} |
fix for "some std.json improvements"
…bug mode at least Add a throwing default case when compiled with asserts on.
|
Rebased, should be ready. |
Issue 7358 - final switch over enum should add throwing default in debug mode
Just want to mention that at least one library solution for bit flags is ready: unstd.typecons.flagEnum. |
Add a throwing default case when compiled with asserts on.
http://d.puremagic.com/issues/show_bug.cgi?id=7358