Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Jonathan M Davis via Digitalmars-d
On Friday, May 19, 2017 9:04:24 PM PDT Stefan Koch via Digitalmars-d wrote: > On Friday, 19 May 2017 at 21:01:09 UTC, Jonathan M Davis wrote: > > Wait, what? Doesn't D specifically _not_ have SFINAE? You can > > use static if to test what compiles, and the branch whose > > condition compiles is

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Dominikus Dittes Scherkl via Digitalmars-d
On Friday, 19 May 2017 at 21:25:22 UTC, Stefan Koch wrote: On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes Scherkl wrote: And it's not visible from the API or documentation - you need to look into the source to disambiguate - I'm not convinced and still consider this bad style. If

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Basile B. via Digitalmars-d
On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes Scherkl wrote: On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote: If a template does trigger a static assert, that static assert is ignored if there is another template in the overload set that could match. Wow. Didn't know

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Stefan Koch via Digitalmars-d
On Friday, 19 May 2017 at 21:23:11 UTC, Dominikus Dittes Scherkl wrote: On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote: If a template does trigger a static assert, that static assert is ignored if there is another template in the overload set that could match. Wow. Didn't know

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Dominikus Dittes Scherkl via Digitalmars-d
On Friday, 19 May 2017 at 21:04:24 UTC, Stefan Koch wrote: If a template does trigger a static assert, that static assert is ignored if there is another template in the overload set that could match. Wow. Didn't know that. Is this really part of the D grammar? Sometimes D is soo cool. Still

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Stefan Koch via Digitalmars-d
On Friday, 19 May 2017 at 21:01:09 UTC, Jonathan M Davis wrote: Wait, what? Doesn't D specifically _not_ have SFINAE? You can use static if to test what compiles, and the branch whose condition compiles is then the on that gets compiled in, which kind of emulates what you'd get with SFINAE,

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Jonathan M Davis via Digitalmars-d
On Friday, May 19, 2017 8:31:52 PM PDT Stefan Koch via Digitalmars-d wrote: > On Friday, 19 May 2017 at 20:23:16 UTC, Dominikus Dittes Scherkl > > wrote: > > On Friday, 19 May 2017 at 17:47:42 UTC, Stefan Koch wrote: > >> On Friday, 19 May 2017 at 17:34:28 UTC, Dominikus Dittes > >> > >> Scherkl

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Stefan Koch via Digitalmars-d
On Friday, 19 May 2017 at 20:23:16 UTC, Dominikus Dittes Scherkl wrote: On Friday, 19 May 2017 at 17:47:42 UTC, Stefan Koch wrote: On Friday, 19 May 2017 at 17:34:28 UTC, Dominikus Dittes Scherkl wrote: [...] the static assert tells what's going on. It it does result in a simple overload not

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Dominikus Dittes Scherkl via Digitalmars-d
On Friday, 19 May 2017 at 17:47:42 UTC, Stefan Koch wrote: On Friday, 19 May 2017 at 17:34:28 UTC, Dominikus Dittes Scherkl wrote: On Friday, 19 May 2017 at 00:14:05 UTC, Stefan Koch wrote: string enumToString(E)(E v) { static assert(is(E == enum), "emumToString is only meant for

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Stefan Koch via Digitalmars-d
On Friday, 19 May 2017 at 17:34:28 UTC, Dominikus Dittes Scherkl wrote: On Friday, 19 May 2017 at 00:14:05 UTC, Stefan Koch wrote: string enumToString(E)(E v) { static assert(is(E == enum), "emumToString is only meant for enums"); Why that assert? We can check it at compiletime.

Re: [Semi-OT] to!string(enumType)

2017-05-19 Thread Dominikus Dittes Scherkl via Digitalmars-d
On Friday, 19 May 2017 at 00:14:05 UTC, Stefan Koch wrote: string enumToString(E)(E v) { static assert(is(E == enum), "emumToString is only meant for enums"); Why that assert? We can check it at compiletime. Doesn't this cry for a constraint? I would use asserts only ever for

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread Stefan Koch via Digitalmars-d
On Thursday, 18 May 2017 at 23:15:46 UTC, ag0aep6g wrote: On 05/19/2017 12:31 AM, Stefan Koch wrote: string enumToString(E)(E v) { static assert(is(E == enum), "emumToString is only meant for enums"); mixin ({ string result = "final switch(v) {\n";

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread H. S. Teoh via Digitalmars-d
On Thu, May 18, 2017 at 11:42:25PM +, Stefan Koch via Digitalmars-d wrote: > On Thursday, 18 May 2017 at 22:31:47 UTC, Stefan Koch wrote: > > > Granted this version will result in undefined behavior if you pass > > something like (cast(ET) 3) to it. > > But the 55x increase in compilation

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread Stefan Koch via Digitalmars-d
On Thursday, 18 May 2017 at 22:31:47 UTC, Stefan Koch wrote: Granted this version will result in undefined behavior if you pass something like (cast(ET) 3) to it. But the 55x increase in compilation speed is well worth it :) This code will replicate to!string behavior perfectly but will

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread ag0aep6g via Digitalmars-d
On 05/19/2017 12:31 AM, Stefan Koch wrote: string enumToString(E)(E v) { static assert(is(E == enum), "emumToString is only meant for enums"); mixin ({ string result = "final switch(v) {\n"; foreach(m;[__traits(allMembers, E)]) { result ~= "\tcase E." ~ m ~ "

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread Moritz Maxeiner via Digitalmars-d
On Thursday, 18 May 2017 at 22:31:47 UTC, Stefan Koch wrote: Hi, I just took a look into commonly used functionality of Phobos. Such as getting the string representation of a enum. [...] Nice, thank you. I dream of a guide to compile time optimization in D. :)

Re: [Semi-OT] to!string(enumType)

2017-05-18 Thread Stefan Koch via Digitalmars-d
On Thursday, 18 May 2017 at 22:31:47 UTC, Stefan Koch wrote: Hi, I just took a look into commonly used functionality of Phobos. Such as getting the string representation of a enum. [...] Using -vcg-ast we see that it expands to ~50 lines.

[Semi-OT] to!string(enumType)

2017-05-18 Thread Stefan Koch via Digitalmars-d
Hi, I just took a look into commonly used functionality of Phobos. Such as getting the string representation of a enum. the following code: import std.conv; enum ET { One, Two } static assert(to!string(ET.One) == "One"); takes about 220 milliseconds to compile. creating a 7.5k object