First an unrelated error. A rewrite of std.typetuple gives the following:
template TypeTuple( TList... )
{
alias TList TypeTuple;
}
template IndexOf( T, TList... )
{
static if( TList.length == 0 )
const size_t IndexOf = 1;
else static if( is( T == typeof( TList[0] ) ) )
const size_t IndexOf = 0;
else
const size_t IndexOf = 1 + IndexOf!( T, TList[1 .. $] );
}
void main()
{
TypeTuple!(int, long) T;
printf( "%u\n", IndexOf!(long, T) );
}
Which does not compile:
C:\code\src\d\test>dmd test
test.d(13): tuple TList is used as a type
test.d(13): Error: can only slice tuple types, not void
test.d(13): Error: void has no value
test.d(13): Error: incompatible types for ((1) + (IndexOf!(long,int))): 'int' and 'void'
test.d(19): template instance test.main.IndexOf!(long,_T_field_0,_T_field_1) error instantiating
This is the error where an extra set of parenthesis are sometimes required for template parameters to evaluate as a type. Easy enough to fix--change line 13 of the above, giving:
template TypeTuple( TList... )
{
alias TList TypeTuple;
}
template IndexOf( T, TList... )
{
static if( TList.length == 0 )
const size_t IndexOf = 1;
else static if( is( T == typeof( TList[0] ) ) )
const size_t IndexOf = 0;
else
const size_t IndexOf = 1 + IndexOf!( T, (TList[1 .. $]) );
}
void main()
{
TypeTuple!(int, long) T;
printf( "%u\n", IndexOf!(long, T) );
}
Compiling the above segfaults DMD.
Comment #1 by sean — 2006-12-26T16:25:24Z
[email protected] wrote:
>
> void main()
> {
> TypeTuple!(int, long) T;
> printf( "%u\n", IndexOf!(long, T) );
> }
>
> Which does not compile:
>
> C:\code\src\d\test>dmd test
> test.d(13): tuple TList is used as a type
Just a quick note. This error (and perhaps some of the others) is
because the TypeTuple declaration above doesn't contain an 'alias'
prefix. The crash demonstrated in the second example is sitll a
problem, however.