take symbol as parameter

Marc jckj33 at gmail.com
Sat Dec 30 13:07:49 UTC 2017


how do I take a symbol as parameter?

for example:

> template nameof(alias S) {
>	import std.array : split;
>	enum nameof = S.stringof.split(".")[$-1];
>}

Works fine for say a enum member such nameof!(myEnum.X) but this:

>	struct S { int v; }
>	S s;
>	writefln(nameof!(s.v)); // should return "v"

return the following error:

> Error: template instance nameof!(v) cannot use local 'v' as 
> parameter to > non-global template nameof(alias S)



More information about the Digitalmars-d-learn mailing list