On Saturday, 9 January 2016 at 12:43:32 UTC, Øivind wrote:
Hi,

Why doesn't this work? Seems like it should:

enum {
        A = 1,
        version(xx) {
                B = 2
        }
}

It's not allowed in the grammar but I agree with you, it could be useful. Recent example where it could:

---
enum VirtualKey
{
   version(linux) VK_UP = 0;  version(Win32) VK_UP = 1,
   ....
}
---

a solution is to define a manifest constant depending on your version() and to use a ternary expression in the enum definition. For me then this works:

---
version(linux) enum ver = true;
else enum ver = false;

enum VirtualKey
{
   VK_UP = (ver) ? 0 : 1,
}
---

Not ideal but it works.

Reply via email to