[Issue 1241] ICE on template instance parameter
Manuel König
ManuelK89 at gmx.net
Wed Aug 1 03:46:00 PDT 2007
d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1241
>
>
> shro8822 at vandals.uidaho.edu changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> CC| |shro8822 at vandals.uidaho.edu
>
>
>
>
> ------- Comment #2 from shro8822 at vandals.uidaho.edu 2007-07-22 12:02 -------
> I have also run into this one. I was trying to use the tuples+templates as
> compile time trees
>
> template Foo(A...)
> {
> template Bar(B...)
> {
> alias A a;
> alias B b;
> }
> }
>
> alias Foo!(Foo!(1,2,3).Bar!(4,5,6)).Bar!(Foo!(7,8,9).Bar!(10,11,12)) tree;
>
> foreach( a; tree.a)
> {
> foreach(aa; a.a);
> foreach(ab; a.b);
> }
> foreach( b; tree.b)
> {
> foreach(ba; b.a);
> foreach(bb; b.b);
> }
>
> Can we please get a fix on this one? It will drop a LOT of barriers to
> elaborate template systems. I have a few really cool things that use it and
> would like to put them in my talk without the disclaimer of "this would work
> but for bug #1241"
>
>
I just discovered a decent workaround. Instead of using templates with
tuple members, just use structs:
Use
struct Tuple(T...)
{
alias T tp;
}
instead of
template Tuple(T...)
{
alias T tp;
}
I tested this with dmd1.020 and rewrote your tree structure using this
trick:
import std.stdio;
struct Foo(A...)
{
struct Bar(B...)
{
alias A a;
alias B b;
}
}
alias Foo!(Foo!(1,2,3).Bar!(4,5,6)).Bar!(Foo!(7,8,9).Bar!(10,11,12)) tree;
void main()
{
foreach( a; tree.a)
{
foreach(aa; a.a) writefln(aa);
foreach(ab; a.b) writefln(ab);
}
foreach( b; tree.b)
{
foreach(ba; b.a) writefln(ba);
foreach(bb; b.b) writefln(bb);
}
}
This prints
1
2
3
4
5
6
7
8
9
10
11
12
for me. Happy coding!
More information about the Digitalmars-d-bugs
mailing list