www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Iterating a typle tuple of templates

reply bearophile <bearophileHUGS lycos.com> writes:
I am allowed to create a type tuple of function templates, but then it seems I
am not allowed to use a static foreach on that type tuple:


import std.typetuple;

int foo(T)(T x) {
    return 0;
}

void main() {
    alias TypeTuple!(foo, foo) t2;
    static assert(t2[0](0) == 0); // OK
    static assert(t2[1](0) == 0); // OK
    foreach (t; t2) {} // Error
}


Is this expected, a bug in my code, a known bug in DMD, a new DMD bug, a
limitation meant to be removed, etc?

Bye,
bearophile
Mar 03 2011
parent reply Jacob Carlborg <doob me.com> writes:
On 2011-03-04 04:37, bearophile wrote:
 I am allowed to create a type tuple of function templates, but then it seems I
am not allowed to use a static foreach on that type tuple:


 import std.typetuple;

 int foo(T)(T x) {
      return 0;
 }

 void main() {
      alias TypeTuple!(foo, foo) t2;
      static assert(t2[0](0) == 0); // OK
      static assert(t2[1](0) == 0); // OK
      foreach (t; t2) {} // Error
 }


 Is this expected, a bug in my code, a known bug in DMD, a new DMD bug, a
limitation meant to be removed, etc?

 Bye,
 bearophile

Maybe you can try something like typeof(t2) in the foreach. -- /Jacob Carlborg
Mar 03 2011
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Jacob Carlborg:

 Maybe you can try something like typeof(t2) in the foreach.

If you mean code like this: import std.typetuple; int foo(T)(T x) { return x; } void main() { alias TypeTuple!(foo, foo) t2; foreach (i, t; typeof(t2)) { pragma(msg, t); assert(t2[i](i) == i); // OK //assert(t(i) == i); // Not OK } } It seems "t" is not useful... Is all this Bugzilla-worthy? Thank you, bye, bearophile
Mar 04 2011
next sibling parent Trass3r <un known.com> writes:
bearophile Wrote:
 It seems "t" is not useful...

Yep, foreach over tuples is kinda messed up. Same with reference tuple foreach: http://d.puremagic.com/issues/show_bug.cgi?id=2411 Direct access doesn't work but accessing via [i] does.
Mar 04 2011
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-03-04 13:19, bearophile wrote:
 Jacob Carlborg:

 Maybe you can try something like typeof(t2) in the foreach.

If you mean code like this: import std.typetuple; int foo(T)(T x) { return x; } void main() { alias TypeTuple!(foo, foo) t2; foreach (i, t; typeof(t2)) { pragma(msg, t); assert(t2[i](i) == i); // OK //assert(t(i) == i); // Not OK } } It seems "t" is not useful...

Yeah, that's really annoying.
 Is all this Bugzilla-worthy?

 Thank you, bye,
 bearophile

-- /Jacob Carlborg
Mar 04 2011
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
bearophile <bearophileHUGS lycos.com> wrote:

 Jacob Carlborg:

 Maybe you can try something like typeof(t2) in the foreach.

If you mean code like this: import std.typetuple; int foo(T)(T x) { return x; } void main() { alias TypeTuple!(foo, foo) t2; foreach (i, t; typeof(t2)) { pragma(msg, t); assert(t2[i](i) == i); // OK //assert(t(i) == i); // Not OK } } It seems "t" is not useful... Is all this Bugzilla-worthy?

Yes. -- Simen
Mar 04 2011