Template args to UDA's
Timon Gehr
timon.gehr at gmx.ch
Sat Jun 1 09:06:03 PDT 2013
On 05/31/2013 04:23 PM, Steven Schveighoffer wrote:
> 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:
>
It is not what happens (otherwise Manu's initial code would work), but
you obviously have a point.
> 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
Agreed.
More information about the Digitalmars-d
mailing list