D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1112 - Allow enums in WithStatements
Summary: Allow enums in WithStatements
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-08 11:51 UTC by Matti Niemenmaa
Modified: 2015-06-09 05:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2007-04-08 11:51:36 UTC
Been asked for a few times, submitting it here for posterity.

enum Enum {
	A = 0, B, C
}

void main() {
	with (Enum) {
		assert (A == 0);
		assert (B == A+1);
		assert (C == B+1);
	}
}

It would be handy if the above worked. A common use case is switching on an enum:

enum Enum {
	A = 0, B, C
}

void main() {
	Enum e;
	with (Enum) switch (e) {
		case A:
		case B:
		case C:
		default: break;
	}
	// the above looks much better than:
	switch (e) {
		case Enum.A:
		case Enum.B:
		case Enum.C:
		default: break;
	}
}
Comment 1 Ary Borenszweig 2007-04-08 13:25:24 UTC
d-bugmail@puremagic.com escribi
Comment 2 Alexey Ivanov 2010-02-14 18:00:46 UTC
Works with DMD 1.055 and DMD 2.040