Phobos' std.conv.to-conversion from enum to string doesn't scale beyond hundreds of enumerators

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Jun 25 08:26:37 UTC 2018


On Monday, June 25, 2018 07:43:53 Per Nordlöw via Digitalmars-d wrote:
> On Monday, 25 June 2018 at 00:35:40 UTC, Jonathan M Davis wrote:
> > Or if you want it to stay an AliasSeq, then just use Alias or
> > AliasSeq on it. e.g.
> >
> > alias members = AliasSeq!(__traits(allMembers, E));
>
> Thanks! Should we prefer this over
>
>      enum members = [__traits(allMembers, E)];

Which is better depends on what you're doing.

    alias members = AliasSeq!(_traits(allMembers, E));

gives you an AliasSeq, whereas

    enum members = [__traits(allMembers, E)];

gives you a dynamic array. The AliasSeq means needing to use templates to
operate on it, whereas using the dynamic array means using CTFE to operate
on it. If you're just going to use a static foreach on it, I wouldn't expect
it to matter much which you use, but ultimately, you'll have to see what
works best with your exact use case. In the long run, once newCTFE is
complete, I suspect that using CTFE where possible instead of templates is
going to be better, but I think that it tends to be less of a clear win with
how inefficient CTFE currently is. But again, it depends on what exactly the
code is doing.

- Jonathan M Davis




More information about the Digitalmars-d mailing list