digitalmars.D.learn - Iterating a typle tuple of templates
- bearophile <bearophileHUGS lycos.com> Mar 03 2011
- Jacob Carlborg <doob me.com> Mar 03 2011
- bearophile <bearophileHUGS lycos.com> Mar 04 2011
- Trass3r <un known.com> Mar 04 2011
- Jacob Carlborg <doob me.com> Mar 04 2011
- "Simen kjaeraas" <simen.kjaras gmail.com> Mar 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
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, bearophile
Maybe 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: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
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









Trass3r <un known.com> 