digitalmars.D.learn - version specific enum members
- Phil Deets (19/19) Oct 29 2009 Hi, is there a way to add members to an enum based on conditional
- Ellery Newcomer (3/26) Oct 29 2009 Unfortunately, that's going to be about the best you can do, unless
- Ary Borenszweig (2/29) Oct 29 2009 Or unless you create an enhancement request. That seems a very valid one...
- Phil Deets (3/31) Oct 29 2009 Done (on the main D list).
- Ary Borenszweig (2/36) Oct 30 2009 I meant a bugzilla enhancement, otherwise it'll get lost in the newsgrou...
- Phil Deets (4/17) Oct 30 2009 Well, I wanted to gauge support for the idea. It turns out I found a
- Daniel Keep (16/37) Oct 29 2009 template Version(char[] ident)
- Phil Deets (15/52) Oct 29 2009 Hey, thanks for the idea. I worked with it a little bit to remove the
Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Oct 29 2009
Phil Deets wrote:Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.Unfortunately, that's going to be about the best you can do, unless you're willing to play with string mixins and their ilk.
Oct 29 2009
Ellery Newcomer wrote:Phil Deets wrote:Or unless you create an enhancement request. That seems a very valid one.Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.Unfortunately, that's going to be about the best you can do, unless you're willing to play with string mixins and their ilk.
Oct 29 2009
On Thu, 29 Oct 2009 18:28:12 -0500, Ary Borenszweig <ary esperanto.org.ar> wrote:Ellery Newcomer wrote:Done (on the main D list).Phil Deets wrote:Or unless you create an enhancement request. That seems a very valid one.Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.Unfortunately, that's going to be about the best you can do, unless you're willing to play with string mixins and their ilk.
Oct 29 2009
Phil Deets wrote:On Thu, 29 Oct 2009 18:28:12 -0500, Ary Borenszweig <ary esperanto.org.ar> wrote:I meant a bugzilla enhancement, otherwise it'll get lost in the newsgroups.Ellery Newcomer wrote:Done (on the main D list).Phil Deets wrote:Or unless you create an enhancement request. That seems a very valid one.Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.Unfortunately, that's going to be about the best you can do, unless you're willing to play with string mixins and their ilk.
Oct 30 2009
On Fri, 30 Oct 2009 06:38:44 -0500, Ary Borenszweig <ary esperanto.org.ar> wrote:Phil Deets wrote:Well, I wanted to gauge support for the idea. It turns out I found a string mixin workaround that works; so it isn't critical for me now.On Thu, 29 Oct 2009 18:28:12 -0500, Ary Borenszweig <ary esperanto.org.ar> wrote:I meant a bugzilla enhancement, otherwise it'll get lost in the newsgroups.Ellery Newcomer wrote:Done (on the main D list).Unfortunately, that's going to be about the best you can do, unless you're willing to play with string mixins and their ilk.Or unless you create an enhancement request. That seems a very valid one.
Oct 30 2009
Phil Deets wrote:Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.template Version(char[] ident) { mixin(`version(`~ident~`) const Version = true; else const Version = false;`); } char[] genEnum(bool flag1, bool flag2) { return "A, B, " ~ (flag1 ? "C, D, " : "") ~ "E, F, " ~ (flag2 ? "G, H, " : "") ~ "G, "; } mixin(genEnum( Version!(`symbol`), Version!(`somethingElse`) )); ... is about the best you can do, I think.
Oct 29 2009
On Fri, 30 Oct 2009 00:03:23 -0500, Daniel Keep <daniel.keep.lists gmail.com> wrote:Phil Deets wrote:Hey, thanks for the idea. I worked with it a little bit to remove the generator function and use multiline strings. This is what I came up with. mixin(q"ENUM enum Tag { A, B, ENUM"~(Version!("symbol")?q"ENUM C, D, ENUM":"")~q"ENUM E, } ENUM"); That's not pretty, but it's good enough for me.Hi, is there a way to add members to an enum based on conditional compilation symbols. I tried enum Tag { A, B, version (symbol) { C, D, } E, } but it doesn't work. I know I could do version (symbol) { enum Tag { A, B, C, D, E } } else { enum Tag { A, B, E } } but I don't want to do that since in my case, there can be quite a few elements outside of the version, and I don't want to repeat them all.template Version(char[] ident) { mixin(`version(`~ident~`) const Version = true; else const Version = false;`); } char[] genEnum(bool flag1, bool flag2) { return "A, B, " ~ (flag1 ? "C, D, " : "") ~ "E, F, " ~ (flag2 ? "G, H, " : "") ~ "G, "; } mixin(genEnum( Version!(`symbol`), Version!(`somethingElse`) )); ... is about the best you can do, I think.
Oct 29 2009