Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 1:35 PM, David Nadlinger wrote: > On Saturday, 4 August 2012 at 11:29:36 UTC, Philippe Sigaud wrote: >> >> Oh, I completely forgot this. Nice code, if I may say so myself :) > > > Huh? It's broken, precisely because of the use of __traits(identifier, …) in > combination with

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 11:29:36 UTC, Philippe Sigaud wrote: Oh, I completely forgot this. Nice code, if I may say so myself :) Huh? It's broken, precisely because of the use of __traits(identifier, …) in combination with string mixins. The example doesn't compile. David

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
On Sat, Aug 4, 2012 at 10:25 AM, David Nadlinger wrote: > An example of what I mean: Try this with your CurryTemplate from dranges: > > --- > import dranges.templates; > > template Foo(A, B) { > pragma(msg, A.stringof, " ", B.stringof); > } > > alias CurryTemplate!Foo FooCurried; > alias FooC

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 07:57:46 UTC, Philippe Sigaud wrote: It uses __traits(parent, ) and __traits(qualifier, ), which are much more 'modern' and well-behaved. An example of what I mean: Try this with your CurryTemplate from dranges: --- import dranges.templates; template Foo(A, B)

Re: Templates and stringof...

2012-08-04 Thread Era Scarecrow
On Saturday, 4 August 2012 at 07:57:46 UTC, Philippe Sigaud wrote: FWIW, I agree with David that using .stringof is a last resort and can lead to nasty bugs. .stringof has a sometime incoherent behavior (I remember it showing the entire code inside a delegate literal) But then, the code sho

Re: Templates and stringof...

2012-08-04 Thread David Nadlinger
On Saturday, 4 August 2012 at 08:06:31 UTC, Jonathan M Davis wrote: On Saturday, August 04, 2012 09:57:36 Philippe Sigaud wrote: For std.reflection that Andrei proposed 2 weeks ago, I feel the internal code will contain many __traits() calls. Nothing to be done about it. __traits is *the* way

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
"Era Scarecrow" > Then doesn't it seem like we're missing a potentially important piece of the puzzle for mixins and templates? very likely my modified template will include you including the same variable twice, but if someone gets lazy then it may not work. > > mixin(bitfieldsOn!("SomeVariabl

Re: Templates and stringof...

2012-08-04 Thread Jonathan M Davis
On Saturday, August 04, 2012 09:57:36 Philippe Sigaud wrote: > For std.reflection that Andrei proposed 2 weeks ago, I feel the internal > code will contain many __traits() calls. Nothing to be done about it. > __traits is *the* way compile-time introspection is done in D. That and std.traits. Betw

Re: Templates and stringof...

2012-08-04 Thread Philippe Sigaud
Le 4 août 2012 00:50, "David Nadlinger" a écrit : > > On Friday, 3 August 2012 at 22:23:23 UTC, Era Scarecrow wrote: >> >> Seems like an ugly hack though (to get this done). Why not have another method of fullpathStringof or something similar? Then again if this is one of the few cases that could

Re: Templates and stringof...

2012-08-03 Thread Era Scarecrow
On Friday, 3 August 2012 at 22:50:54 UTC, David Nadlinger wrote: On Friday, 3 August 2012 at 22:44:28 UTC, Andrej Mitrovic wrote: In fact, this should really be put into Phobos so everyone can benefit rather than implementing this internally as a private template of bitmanip. No, it shouldn't

Re: Templates and stringof...

2012-08-03 Thread Era Scarecrow
On Friday, 3 August 2012 at 22:47:52 UTC, David Nadlinger wrote: On Friday, 3 August 2012 at 22:23:23 UTC, Era Scarecrow wrote: Seems like an ugly hack though (to get this done). Why not have another method of fullpathStringof or something similar? Then again if this is one of the few cases tha

Re: Templates and stringof...

2012-08-03 Thread David Nadlinger
On Friday, 3 August 2012 at 22:44:28 UTC, Andrej Mitrovic wrote: On 8/4/12, Andrej Mitrovic wrote: Courtesy of Philippe Sigaud, slightly edited to my style: In fact, this should really be put into Phobos so everyone can benefit rather than implementing this internally as a private template

Re: Templates and stringof...

2012-08-03 Thread David Nadlinger
On Friday, 3 August 2012 at 22:23:23 UTC, Era Scarecrow wrote: Seems like an ugly hack though (to get this done). Why not have another method of fullpathStringof or something similar? Then again if this is one of the few cases that could benefit from it, then maybe we should make it ugly so no

Re: Templates and stringof...

2012-08-03 Thread David Nadlinger
On Friday, 3 August 2012 at 21:33:35 UTC, Era Scarecrow wrote: Because a string doesn't hold it's type information for size checking. int = 4 bytes or 32 bits string = Just emit the check into the code you generate. It also checks for unsuitable types like structs and floats; can't

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/4/12, Andrej Mitrovic wrote: > On 8/3/12, Era Scarecrow wrote: >> Now, how do I get the template's stringof to print out 'i_num.i' >> and not 'i'? > > Courtesy of Philippe Sigaud, slightly edited to my style: In fact, this should really be put into Phobos so everyone can benefit rather th

Re: Templates and stringof...

2012-08-03 Thread Era Scarecrow
On Friday, 3 August 2012 at 22:18:25 UTC, Andrej Mitrovic wrote: On 8/4/12, Andrej Mitrovic wrote: On 8/3/12, Era Scarecrow wrote: Now, how do I get the template's stringof to print out 'i_num.i' and not 'i'? snip Ahh crap, it doesn't return the *instance* name. Sorry!! Maybe there ca

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/4/12, Andrej Mitrovic wrote: > On 8/3/12, Era Scarecrow wrote: >> Now, how do I get the template's stringof to print out 'i_num.i' >> and not 'i'? > snip Ahh crap, it doesn't return the *instance* name. Sorry!! Maybe there can be a fix though, I'll give it a try..

Re: Templates and stringof...

2012-08-03 Thread Andrej Mitrovic
On 8/3/12, Era Scarecrow wrote: > Now, how do I get the template's stringof to print out 'i_num.i' > and not 'i'? Courtesy of Philippe Sigaud, slightly edited to my style: /** Return the fully qualified name of a symbol. Implemented by Philippe Sigaud in the D Templates book. See h

Re: Templates and stringof...

2012-08-03 Thread Era Scarecrow
On Friday, 3 August 2012 at 21:19:08 UTC, David Nadlinger wrote: On Friday, 3 August 2012 at 21:02:22 UTC, Era Scarecrow wrote: Now, how do I get the template's stringof to print out 'i_num.i' and not 'i'? You don't. Using .stringof in conjunction with string mixins is The Wrong Thing (tm) in

Re: Templates and stringof...

2012-08-03 Thread David Nadlinger
On Friday, 3 August 2012 at 21:02:22 UTC, Era Scarecrow wrote: Now, how do I get the template's stringof to print out 'i_num.i' and not 'i'? You don't. Using .stringof in conjunction with string mixins is The Wrong Thing (tm) in virtually all cases. What do you want to achieve? Why can't yo

Templates and stringof...

2012-08-03 Thread Era Scarecrow
While working on bitfields code I've found a unique scenario that poses some annoyances when generating the code. template XYZ(alias x) { enum XYZ = x.stringof ~ "=100;"; } struct I { int i;} I i_num; int n; mixin(XYZ!(i_num.i)); //cannot find variable i mixin(XYZ!(n)); the mixins beco