version in enum

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 9 18:01:33 PST 2016


On Saturday, January 09, 2016 13:32:49 Adam D. Ruppe via Digitalmars-d-learn wrote:
> On Saturday, 9 January 2016 at 12:43:32 UTC, Øivind wrote:
> > Why doesn't this work? Seems like it should:
>
> D defines version to only work on *complete* blocks. You're
> trying to use it on a partial block there.
>
> You'll have to try something else. Perhaps copying the whole enum
> in the different version blocks....

Yeah. That's what we do in core.time.ClockType. You have to duplicate the
entire enum for each version with each enum declaration listing exactly
which members exist in that version, which is an annoying amount of code
duplication, but unless you did something with string mixins to generate
your enum, and it generated the actual declaration for you with all of the
separate version blocks, you're stuck with that duplication. And I rather
doubt that going to the effort of generating a string mixin just so that you
can list each member exactly once is worth it.

A related thing to consider (depending on what the enum is used for) is that
with a differing list of enum members in each version, unless you specify
the value of each enum member explictly, they'll differ in each version. In
many cases, that probably doesn't matter, but it some, it would. So, it's
something to think about when versioning an enum.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list