Re: dmd: enum to!string slows down compilation

2020-12-29 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 29 December 2020 at 22:42:16 UTC, kdevel wrote: Why is the enum to!string conversion so slow? ~~~slowenumtostringconversion.d private enum S { A, B, C, D, }; [...] one factor is all the template constraints that are evaluated until the right std.conv.to overload gets selected.

dmd: enum to!string slows down compilation

2020-12-29 Thread kdevel via Digitalmars-d-learn
Why is the enum to!string conversion so slow? ~~~slowenumtostringconversion.d private enum S { A, B, C, D, }; version (fast) { string resolve (E) (E e) { static foreach (m; __traits (allMembers, E)) if (e == __traits (getMember, E, m)) return m; assert

Re: print enum value rather name from enum X : string

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 13, 2018 01:55:59 Marc via Digitalmars-d-learn wrote: > Thanks for you always well-thought-out answer. I was going to > print it with writefln() calls more than anywhere else so to > avoid casts in all those places, which would make it ugly, I just > used > > > enum foo = "a";

Re: print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
to strings, you get their actual values. It's just that those modules specifically grab the names of the enum members when converting enums to strings, since in all cases other than with strings, it's generally desirable that when converting an enum member to string, you get the name

Re: print enum value rather name from enum X : string

2018-02-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, February 12, 2018 17:07:50 Marc via Digitalmars-d-learn wrote: > If I have an enum like this: > > enum S : string { > > > > foo = "a", > > baa = "b" > > > >} > > when I printed it, to my surprise I get the enum

print enum value rather name from enum X : string

2018-02-12 Thread Marc via Digitalmars-d-learn
If I have an enum like this: enum S : string { foo = "a", baa = "b" } when I printed it, to my surprise I get the enum field name rather value: writefln("%s v%s", S.foo, S.baa); output: foo vbaa instead of a vb a cast solves it

Re: enum to string

2009-03-14 Thread bearophile
Daniel Keep: template Range(int n) If some of you needs a version that takes 1 or 2 or 3 arguments, for the start, stop and stride, take a look at my dlibs: http://www.fantascienza.net/leonardo/so/dlibs/templates.html Bye, bearophile

Re: enum to string

2009-03-13 Thread Ary Borenszweig
Lionello Lunesu wrote: Brad Roberts bra...@bellevue.puremagic.com wrote in message news:alpine.deb.2.00.0903121755240.4...@bellevue.puremagic.com... That said, I don't think this really helps the desired usecase much. It's useful, don't get me wrong, but still requires code to build up the

Re: enum to string

2009-03-13 Thread Daniel Keep
Ary Borenszweig wrote: Lionello Lunesu wrote: Brad Roberts bra...@bellevue.puremagic.com wrote in message news:alpine.deb.2.00.0903121755240.4...@bellevue.puremagic.com... That said, I don't think this really helps the desired usecase much. It's useful, don't get me wrong, but still

Re: enum to string

2009-03-12 Thread Robert Fraser
Jarrett Billingsley wrote: There's also std.typecons which has an enum generator that will create toString and I think fromString functions as well. Which should be easily portable to D1.

Re: enum to string

2009-03-12 Thread Lionello Lunesu
Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a patch to the DMD source was not really what you expected. I just got so anxious! L.

Re: enum to string

2009-03-12 Thread Nick Sabalausky
Lionello Lunesu l...@lunesu.remove.com wrote in message news:gpc4es$30a...@digitalmars.com... Nick Sabalausky wrote: Is there any way to do this (preferably in D1) with reflection? (ie, without having to manually create a conversion func/lookup for every value of every enum.)

Re: enum to string

2009-03-12 Thread Nick Sabalausky
Lionello Lunesu l...@lunesu.remove.com wrote in message news:gpc4j3$30a...@digitalmars.com... Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a patch to the DMD source was not really what you expected. I just got so anxious! L. Hey, solutions are solutions :) In fact

Re: enum to string

2009-03-12 Thread Lionello Lunesu
Your attachment is zero-byte. Oops... Try this one.. /* Create a TupleExp out of the fields of the struct e: * (e.field0, e.field1, e.field2, ...) */ e = e-semantic(sc);// do this before turning on noaccesscheck

Re: enum to string

2009-03-12 Thread Lionello Lunesu
Nick Sabalausky wrote: Lionello Lunesu l...@lunesu.remove.com wrote in message news:gpc4j3$30a...@digitalmars.com... Oops, sorry, I didn't notice this was the .learn newsgroup. I guess a patch to the DMD source was not really what you expected. I just got so anxious! L. Hey, solutions are

Re: enum to string

2009-03-12 Thread Lionello Lunesu
cr*p, I've pasted too little. Try this one instead.. I'll use a proper diff tool next time.. /* If e.tupleof */ if (ident == Id::tupleof) { /* Create a TupleExp out of the fields of the struct e: * (e.field0, e.field1, e.field2,

Re: enum to string

2009-03-12 Thread Lionello Lunesu
//src\dmd\mtype.c, line 5025 (in TypeEnum::dotExp, after the #endif): /* If e.tupleof */ if (ident == Id::tupleof) { /* Create a TupleExp out of the fields of the struct e: * (e.field0, e.field1, e.field2, ...) */ e = e-semantic(sc); // do this before turning

Re: enum to string

2009-03-12 Thread Brad Roberts
On Thu, 12 Mar 2009, BCS wrote: Reply to Lionello, cr*p, I've pasted too little. Try this one instead.. I'll use a proper diff tool next time.. you client is messing with you, paste-bin the sucker or add it to a bugzilla item Just to be sure the two don't get combined (I know

Re: enum to string

2009-03-10 Thread Jarrett Billingsley
On Tue, Mar 10, 2009 at 9:54 PM, Nick Sabalausky a...@a.a wrote: MIURA Masahiro echocham...@gmail.com wrote in message news:gp730i$30e...@digitalmars.com... In D2: enum Shape: string {    Square = Square,    Circle = Circle, } void main() {    assert(cast(string) Shape.Square