Re: Classes as enums in D?

2015-11-30 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 30 November 2015 at 08:08:20 UTC, Meta wrote: class WhiteKey { private immutable int halfStepsToNext; private immutable int halfStepsToPrevious; enum { A = new WhiteKey(2, 2), B = new WhiteKey(2, 1), C =

Re: Classes as enums in D?

2015-11-30 Thread Andrew LaChance via Digitalmars-d-learn
On Monday, 30 November 2015 at 08:08:20 UTC, Meta wrote: This doesn't quite work in D; you'd have to make each WhiteKey const (which is probably not a bad idea anyway if you're using it like an enum). However, it's better to just do this with plain old value-type structs. It's exactly the same

Re: Classes as enums in D?

2015-11-30 Thread Andrew LaChance via Digitalmars-d-learn
On Monday, 30 November 2015 at 07:54:49 UTC, Rikki Cattermole wrote: enums don't have to be integral, but for performance reasons it is for the best. enum Foo : string { A = "a", B = "b", C = "d", ERROR = "What are you talking about?" } void main() { import std.stdio :

Re: Classes as enums in D?

2015-11-30 Thread Meta via Digitalmars-d-learn
On Monday, 30 November 2015 at 07:48:37 UTC, Andrew LaChance wrote: Hello, D has intrigued me for a while, and I thought I would finally read up on it! I've been reading "Programming in D" by Ali Çehreli and I've been thinking about how I can use the language in a side project I'm working

Re: Classes as enums in D?

2015-11-30 Thread Mike Parker via Digitalmars-d-learn
On Monday, 30 November 2015 at 07:58:43 UTC, Andrew LaChance wrote: Oh interesting. So you are saying I could have a struct WhiteKey {...} and then an enum that extends WhiteKey? enums can't *extend* anything. You can do this: struct WhiteKeyS { immutable int halfStepsToPrevious;

Re: Classes as enums in D?

2015-11-30 Thread Rikki Cattermole via Digitalmars-d-learn
On 30/11/15 8:58 PM, Andrew LaChance wrote: On Monday, 30 November 2015 at 07:54:49 UTC, Rikki Cattermole wrote: enums don't have to be integral, but for performance reasons it is for the best. enum Foo : string { A = "a", B = "b", C = "d", ERROR = "What are you talking about?"

Re: Classes as enums in D?

2015-11-30 Thread Meta via Digitalmars-d-learn
On Monday, 30 November 2015 at 10:22:54 UTC, Marc Schütz wrote: You're misinterpreting this: enum X { A = new Object, B = new Object, } void main() { import std.stdio; writeln(cast(void*) X.A); writeln(cast(void*) X.A); } # output:

Classes as enums in D?

2015-11-29 Thread Andrew LaChance via Digitalmars-d-learn
Hello, D has intrigued me for a while, and I thought I would finally read up on it! I've been reading "Programming in D" by Ali Çehreli and I've been thinking about how I can use the language in a side project I'm working on, porting it from java to D. One of the uncommonly-used features of

Re: Classes as enums in D?

2015-11-29 Thread Rikki Cattermole via Digitalmars-d-learn
On 30/11/15 8:48 PM, Andrew LaChance wrote: Hello, D has intrigued me for a while, and I thought I would finally read up on it! I've been reading "Programming in D" by Ali Çehreli and I've been thinking about how I can use the language in a side project I'm working on, porting it from java to