Re: enum inheritance

2013-08-02 Thread bearophile
JS: It would be nice to be able to use enums in a hierarchical way: enum colors { enum Red { RedOrange, ... } enum Green { GreenBlue, ...} enum Blue { BlueYellow, ... } ... } which would be the same as the flattened version, enum colors { Red, RedOrange, ..., Green, GreenBlu

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 19:24:27 UTC, Dicebot wrote: On Monday, 15 July 2013 at 18:26:26 UTC, JS wrote: Original I had it as a class. I'm not sure if it matters much between a class and a struct though? It does matter a lot. structs are value types, classes are polymorphic reference types.

Re: enum inheritance

2013-07-15 Thread Dicebot
On Monday, 15 July 2013 at 18:26:26 UTC, JS wrote: Original I had it as a class. I'm not sure if it matters much between a class and a struct though? It does matter a lot. structs are value types, classes are polymorphic reference types. There is a nice summary table in docs: http://dlang.org

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 13:47:10 UTC, Dicebot wrote: On Monday, 15 July 2013 at 13:01:05 UTC, JS wrote: ... I see. No, unfortunately, I am currently not aware of a way to make symbol act as type and and value at the same time. However it is worth noting that you use plenty of excessive

Re: enum inheritance

2013-07-15 Thread Dicebot
On Monday, 15 July 2013 at 13:01:05 UTC, JS wrote: ... I see. No, unfortunately, I am currently not aware of a way to make symbol act as type and and value at the same time. However it is worth noting that you use plenty of excessive attributes. Currently it is not a compiler error but make

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 11:00:59 UTC, Dicebot wrote: On Monday, 15 July 2013 at 04:24:59 UTC, JS wrote: ... I think closest solution you can get is having bunch of private enum definitions and combining them into single public one via compile-time reflection. Something like "mixin(genera

Re: enum inheritance

2013-07-15 Thread Namespace
On Monday, 15 July 2013 at 10:23:22 UTC, JS wrote: On Monday, 15 July 2013 at 10:17:08 UTC, JS wrote: On Monday, 15 July 2013 at 08:20:20 UTC, Namespace wrote: Maybe this way? final abstract class Colors { enum Red { RedOrange } enum Green { GreenBlue} enum Blue {

Re: enum inheritance

2013-07-15 Thread Dicebot
On Monday, 15 July 2013 at 04:24:59 UTC, JS wrote: ... I think closest solution you can get is having bunch of private enum definitions and combining them into single public one via compile-time reflection. Something like "mixin(generateEnum!(Red, Green, blue))".

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 10:17:08 UTC, JS wrote: On Monday, 15 July 2013 at 08:20:20 UTC, Namespace wrote: Maybe this way? final abstract class Colors { enum Red { RedOrange } enum Green { GreenBlue} enum Blue { BlueYellow } } void main() { Colors.Red foo

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 08:20:20 UTC, Namespace wrote: Maybe this way? final abstract class Colors { enum Red { RedOrange } enum Green { GreenBlue} enum Blue { BlueYellow } } void main() { Colors.Red foo = Colors.Red.RedOrange; assert(foo >= Color

Re: enum inheritance

2013-07-15 Thread Namespace
Maybe this way? final abstract class Colors { enum Red { RedOrange } enum Green { GreenBlue} enum Blue { BlueYellow } } void main() { Colors.Red foo = Colors.Red.RedOrange; assert(foo >= Colors.Red.min && foo <= Colors.Red.max); }

Re: enum inheritance

2013-07-15 Thread JS
On Monday, 15 July 2013 at 07:37:36 UTC, Mike Parker wrote: On Monday, 15 July 2013 at 04:27:42 UTC, JS wrote: BTW, the usefulness is to group sub-enums into the same range. This would make it easy/efficient to branch over a range in the enum: if (v in colors.Red) { v is a color in red } ins

Re: enum inheritance

2013-07-15 Thread Mike Parker
On Monday, 15 July 2013 at 04:27:42 UTC, JS wrote: BTW, the usefulness is to group sub-enums into the same range. This would make it easy/efficient to branch over a range in the enum: if (v in colors.Red) { v is a color in red } instead of if (v is color.Red || v is color.RedOrange || ...)

Re: enum inheritance

2013-07-14 Thread JS
On Monday, 15 July 2013 at 04:27:42 UTC, JS wrote: BTW, the usefulness is to group sub-enums into the same range. This would make it easy/efficient to branch over a range in the enum: if (v in colors.Red) { v is a color in red } instead of if (v is color.Red || v is color.RedOrange || ...)

Re: enum inheritance

2013-07-14 Thread JS
BTW, the usefulness is to group sub-enums into the same range. This would make it easy/efficient to branch over a range in the enum: if (v in colors.Red) { v is a color in red } instead of if (v is color.Red || v is color.RedOrange || ...)

enum inheritance

2013-07-14 Thread JS
It would be nice to be able to use enums in a hierarchical way: enum colors { enum Red { RedOrange, ... } enum Green { GreenBlue, ...} enum Blue { BlueYellow, ... } ... } which would be the same as the flattened version, enum colors { Red, RedOrange, ..., Green, GreenBlue, ...

Re: enum inheritance?

2011-08-14 Thread Ary Manzana
On 8/13/11 9:42 PM, Simen Kjaeraas wrote: On Sun, 14 Aug 2011 01:15:29 +0200, mimocrocodil <[email protected]> wrote: Hi! I am want to extend available enum to provide more items to them. How I can do this job without manual copying of exsisting enum items? If what you want is a new enum t

Re: enum inheritance?

2011-08-13 Thread Simen Kjaeraas
On Sun, 14 Aug 2011 01:15:29 +0200, mimocrocodil <[email protected]> wrote: Hi! I am want to extend available enum to provide more items to them. How I can do this job without manual copying of exsisting enum items? If what you want is a new enum that contains the values of an existing

Re: enum inheritance?

2011-08-13 Thread Jonathan M Davis
On Saturday, August 13, 2011 23:15:29 mimocrocodil wrote: > Hi! > > I am want to extend available enum to provide more items to them. > > How I can do this job without manual copying of exsisting enum items? You can't. An enum has a fixed set of values. You can't extend it in any way, shape, or

enum inheritance?

2011-08-13 Thread mimocrocodil
Hi! I am want to extend available enum to provide more items to them. How I can do this job without manual copying of exsisting enum items?