Thread overview
Iterating a typle tuple of templates
Mar 04, 2011
bearophile
Mar 04, 2011
Jacob Carlborg
Mar 04, 2011
bearophile
Mar 04, 2011
Trass3r
Mar 04, 2011
Jacob Carlborg
Mar 04, 2011
Simen kjaeraas
March 04, 2011
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
March 04, 2011
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
March 04, 2011
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
March 04, 2011
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.
March 04, 2011
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
March 04, 2011
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