Template args to UDA's
Kenji Hara
k.hara.pg at gmail.com
Tue May 28 08:45:07 PDT 2013
It looks reasonable, but in general case it would introduce not trivial
semantic issue.
Based on the current D language spec, prefix attribute is just rewritten to
blocked attribute.
@attribute("target", T) void func(string T)() {}
to:
@attribute("target", T) {
void func(string T)() {}
}
And block attribute can contain other declarations.
@attribute("target", T) {
enum str = T.stringof;
void func(string T)() {}
}
Well, if the enhancement is implemented, T would be deduced by the each
call of template function foo. Then the enum value would become
undeterministic.
I think it is not implementable.
Kenji Hara
2013/5/28 Manu <turkeyman at gmail.com>
> Indeed it does.
> It's a bit obtuse though having to wrap my function up in an outer
> template just to scope the template arg correctly.
>
> Do you think it's reasonable that an attribute should be scoped such that
> it can see the template args of the declaration it's bound to?
> It kinda makes sense, an attribute is intrinsically connected to the
> declaration, so it should be able to access any template args given...
>
>
> On 28 May 2013 23:51, Kenji Hara <k.hara.pg at gmail.com> wrote:
>
>> 2013/5/28 Manu <turkeyman at gmail.com>
>>
>>> So I've run into an expression I need to be able to implement std.simd
>>> properly for GDC/LDC.
>>>
>>> Doesn't work:
>>> @attribute("target", T) void func(string T)(...);
>>>
>>> In this case, currently, the UDA can't receive the template arg that was
>>> given to the function.
>>>
>>> I require that attributes on templates be able to make use of the
>>> template args, since the template arg given may affect the attribute in
>>> some circumstances.
>>>
>>
>> This code works.
>>
>> string attribute(string, string s) { return s; }
>>
>> //@attribute("target", T) void func(string T)() {}
>> template func(string T)
>> {
>> @attribute("target", T) void func() {}
>> }
>>
>> void main()
>> {
>> alias f1 = func!"a";
>> alias f2 = func!"b";
>> pragma(msg, __traits(getAttributes, f1)); // "a"
>> pragma(msg, __traits(getAttributes, f2)); // "b"
>> f1();
>> f2();
>> }
>>
>> Kenji Hara
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130529/d6e6aa1a/attachment.html>
More information about the Digitalmars-d
mailing list