digitalmars.D.learn - UDAs on templates
- John Colvin (7/7) Oct 16 2013 It seems that __traits(getAttributes, T) returns an empty tuple
- Dicebot (9/16) Oct 16 2013 I think this gets re-written like this:
- Dicebot (3/3) Oct 16 2013 (quick experiments show that one can't attached UDA to template
- Max Samukha (6/9) Oct 16 2013 It is understandable why the attribute is transferred to the
- Max Samukha (2/4) Oct 16 2013 Impossible, ignore
- Max Samukha (7/12) Oct 16 2013 @(1)
- Dicebot (10/16) Oct 16 2013 @(1)
- Max Samukha (4/24) Oct 16 2013 That sucks. Then, getAttributes (and other traits dealing with
- Jacob Carlborg (5/8) Oct 16 2013 Currenrly one need to call __traits(getOverloads) and then iterate of
It seems that __traits(getAttributes, T) returns an empty tuple for any template (or template function) T, no matter what UDAs T has been given. Am I doing something wrong? (1) void foo(T)(){} pragma(msg, __traits(getAttributes, foo)); // tuple() pragma(msg, __traits(getAttributes, foo!int)); // tuple(1)
Oct 16 2013
On Wednesday, 16 October 2013 at 12:26:34 UTC, John Colvin wrote:It seems that __traits(getAttributes, T) returns an empty tuple for any template (or template function) T, no matter what UDAs T has been given. Am I doing something wrong? (1) void foo(T)(){} pragma(msg, __traits(getAttributes, foo)); // tuple() pragma(msg, __traits(getAttributes, foo!int)); // tuple(1)I think this gets re-written like this: template foo(T) { (1) void foo() {} } ..which does explain the observed behavior. As a workaround you can define some default guard value of T and assert inside foo() call if it is actually ever used.
Oct 16 2013
(quick experiments show that one can't attached UDA to template symbol itself by any means - weird limitation, don't know the rationale behind this)
Oct 16 2013
On Wednesday, 16 October 2013 at 12:37:23 UTC, Dicebot wrote:(quick experiments show that one can't attached UDA to template symbol itself by any means - weird limitation, don't know the rationale behind this)It is understandable why the attribute is transferred to the instantiation of the function template, though I'd rather have the same set of attributes on both the template and its instantiations in this case. There is no reason why attributes cannot be applied to templates themselves. I think that's a bug.
Oct 16 2013
On Wednesday, 16 October 2013 at 13:12:39 UTC, Max Samukha wrote:I'd rather have the same set of attributes on both the template and its instantiationsImpossible, ignore
Oct 16 2013
On Wednesday, 16 October 2013 at 13:14:31 UTC, Max Samukha wrote:On Wednesday, 16 October 2013 at 13:12:39 UTC, Max Samukha wrote:(1) template Foo(T : int) {} (2) template Foo(T : short) {} __traits(getAttributes, Foo) == ? The current semantics seems quite reasonable.I'd rather have the same set of attributes on both the template and its instantiationsImpossible, ignore
Oct 16 2013
On Wednesday, 16 October 2013 at 13:24:59 UTC, Max Samukha wrote:(1) template Foo(T : int) {} (2) template Foo(T : short) {} __traits(getAttributes, Foo) == ? The current semantics seems quite reasonable.(1) void foo(int) {} (2) void foo(double) {} pragma(msg, __traits(getAttributes, foo)); void main() {} // Compilation output: // // tuple(1)
Oct 16 2013
On Wednesday, 16 October 2013 at 13:38:44 UTC, Dicebot wrote:On Wednesday, 16 October 2013 at 13:24:59 UTC, Max Samukha wrote:That sucks. Then, getAttributes (and other traits dealing with overload sets) should return an empty set, a union or accept a pattern to match against the members of the overload set.(1) template Foo(T : int) {} (2) template Foo(T : short) {} __traits(getAttributes, Foo) == ? The current semantics seems quite reasonable.(1) void foo(int) {} (2) void foo(double) {} pragma(msg, __traits(getAttributes, foo)); void main() {} // Compilation output: // // tuple(1)
Oct 16 2013
On 2013-10-16 16:05, Max Samukha wrote:That sucks. Then, getAttributes (and other traits dealing with overload sets) should return an empty set, a union or accept a pattern to match against the members of the overload set.Currenrly one need to call __traits(getOverloads) and then iterate of the result and call __traits(getAttributes) on each item. -- /Jacob Carlborg
Oct 16 2013