Template args to UDA's
Steven Schveighoffer
schveiguy at yahoo.com
Fri May 31 07:23:49 PDT 2013
On Fri, 31 May 2013 06:47:07 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:
> @attribute("target", T) void func(string T)() {}
>
> would simply need to be treated like:
>
> template func(string T){
> @attribute("target", T) void func() {}
> }
In fact, today's current semantics suggest this is exactly what happens:
import std.stdio;
@("a") void func(T)(T t) {}
void main()
{
writefln("func attributes: %s", [__traits(getAttributes, func)]);
writefln("func!int attributes: %s", [__traits(getAttributes,
func!int)]);
}
Output:
func attributes: []
func!int attributes: ["a"]
If the attributes applied only to the template symbol, then you would
think func would have the attribute a.
Plus, the idea that you must actually instantiate the template to get an
attribute to apply REALLY suggests the attribute should be aware of the
template parameters.
-Steve
More information about the Digitalmars-d
mailing list