www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - UDA tuple flattening

reply "jerro" <a a.com> writes:
I noticed that this doesn't work with the latest DMD from github:

import std.typetuple;

struct Foo{}
struct Bar{}

alias TypeTuple!(Foo, Bar) FooBar;

 FooBar
void foo(){}

pragma(msg, __traits(getAttributes, foo));

When trying to compile this, the compiler prints:

a.d(6): Error: cannot form tuple of tuples
tuple(((Foo, Bar)))

Would it not make sense for the tuples of attributes to be 
automatically flattened, as tuples are in other places? This 
would also allow one to do stuff like this, which I think could 
be very useful:

static if(something)
     alias TypeTuple!(A, B, C) fooAttributes;
else
     alias TypeTuple!(C, D) fooAttributes;

 fooAttributes
void foo(){}
Dec 18 2012
parent "Max Samukha" <maxsamukha gmail.com> writes:
On Tuesday, 18 December 2012 at 17:31:49 UTC, jerro wrote:
 I noticed that this doesn't work with the latest DMD from 
 github:

 import std.typetuple;

 struct Foo{}
 struct Bar{}

 alias TypeTuple!(Foo, Bar) FooBar;

  FooBar
 void foo(){}

 pragma(msg, __traits(getAttributes, foo));

 When trying to compile this, the compiler prints:

 a.d(6): Error: cannot form tuple of tuples
 tuple(((Foo, Bar)))

 Would it not make sense for the tuples of attributes to be 
 automatically flattened, as tuples are in other places? This 
 would also allow one to do stuff like this, which I think could 
 be very useful:

 static if(something)
     alias TypeTuple!(A, B, C) fooAttributes;
 else
     alias TypeTuple!(C, D) fooAttributes;

  fooAttributes
 void foo(){}
Definitely a bug.
Dec 18 2012