www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - stringof of an TemplateAliasParameter

reply Matthias Walter <Matthias.Walter st.ovgu.de> writes:
Hello,

suppose you have the following template:

| template Foo (alias X)
| {
|   const char[] Foo = X.stringof ~ " = null;";
| }

... and instanciate it with a struct member ...

| mixin (Foo !(mystruct.member));

... this code becomes "member = null;", although I'd like it to be
"mystruct.member = null;" Is this intended behavior? .stringof seems to return
only sort of a short version of the name.

Of course I could make my template accept a string "mystruct.member" instead of
an alias to make it work, but I thought this would be more comfortable to let
the user call my mixins with variables instead of strings, containing
variables! Or is there another way to achieve my needs?

best regards
Matthias Walter
May 18 2008
parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 18 May 2008 21:33:35 +0200, Matthias Walter  =

<Matthias.Walter st.ovgu.de> wrote:

 Hello,

 suppose you have the following template:

 | template Foo (alias X)
 | {
 |   const char[] Foo =3D X.stringof ~ " =3D null;";
 | }

 ... and instanciate it with a struct member ...

 | mixin (Foo !(mystruct.member));

 ... this code becomes "member =3D null;", although I'd like it to be  =
 "mystruct.member =3D null;" Is this intended behavior? .stringof seems=
to =
 return only sort of a short version of the name.

 Of course I could make my template accept a string "mystruct.member"  =
 instead of an alias to make it work, but I thought this would be more =
=
 comfortable to let the user call my mixins with variables instead of  =
 strings, containing variables! Or is there another way to achieve my  =
 needs?

 best regards
 Matthias Walter
You can use the meta library in Pyd. http://www.dsource.org/projects/pyd/browser/trunk/infrastructure/meta struct foo { int bar; } pragma(msg, qualifiednameof!(foo.bar)); // prints somemodule.foo.bar
May 19 2008