version in enum
Basile B. via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 9 05:41:23 PST 2016
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.
More information about the Digitalmars-d-learn
mailing list