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 00:35:40 UTC 2018


On Sunday, June 24, 2018 23:53:09 Timoses via Digitalmars-d wrote:
> On Sunday, 24 June 2018 at 23:34:49 UTC, Per Nordlöw wrote:
> > Provided that
> >
> >     __traits(allMembers, E)
> >
> > is a cheap operation as it's called once for every enumerator.
> > I could get it out of the loop; if I do as
> >
> >     @property string toString() @safe pure nothrow @nogc
> >     {
> >
> >         final switch (_enum)
> >         {
> >
> >             enum members = __traits(allMembers, E);
>
> enum members = [_traits(allMembers, E)];
>
> seems to work

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));

Given that the result of __traits in this case is an AliasSeq, I have no
idea why the gramar doesn't allow you to just use the result of __traits
directly as an AliasSeq with something like

alias members = __traits(allMembers, E);

but it doesn't. So, you have to wrap it, dumb as that may be. There's a bug
report about it in bugzilla somewhere.

- Jonathan M Davis




More information about the Digitalmars-d mailing list