digitalmars.D.learn - Iterating a typle tuple of templates
- bearophile (14/14) Mar 03 2011 I am allowed to create a type tuple of function templates, but then it s...
- Jacob Carlborg (4/18) Mar 03 2011 Maybe you can try something like typeof(t2) in the foreach.
- bearophile (18/19) Mar 04 2011 If you mean code like this:
- Trass3r (4/5) Mar 04 2011 Yep, foreach over tuples is kinda messed up.
- Jacob Carlborg (4/23) Mar 04 2011 --
- Simen kjaeraas (4/21) Mar 04 2011 Yes.
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
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, bearophileMaybe you can try something like typeof(t2) in the foreach. -- /Jacob Carlborg
Mar 03 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
Mar 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.
Mar 04 2011
On 2011-03-04 13:19, bearophile wrote:Jacob Carlborg:Yeah, that's really annoying.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-- /Jacob Carlborg
Mar 04 2011
bearophile <bearophileHUGS lycos.com> wrote:Jacob Carlborg:Yes. -- SimenMaybe 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?
Mar 04 2011