On 29 May 2013 10:46, Diggory <diggsey@googlemail.com> wrote:
On Tuesday, 28 May 2013 at 13:41:42 UTC, Manu wrote:
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.

Can you not move the template outside the attribute like this?:

template func(string T) {
    @attribute("target", T) void func(...);
}

Yes, that's Kenji's initial suggestion, which I can use for now, but it feels like a workaround.
It feels pretty lame to have to wrap select functions in an arbitrary outer scope, and it also has some subtle implications; how does auto-complete/intellisense see it? As a template, or as whatever it resolves to?
The latter would imply some pretty powerful semantic analysis, and if there's static logic inside the template? The IDE basically won't work properly for any of these functions.

Either way, the attribute certainly looks like it's part of the declaration, I think any reasoning programmer would assume that it is. It's only a DMD implementation detail that says otherwise, and it's not particularly intuitive to a programmer.