mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-12 02:43:14 +01:00
I've implemented it this way since it doesn't require any changes in the frontend. However, I think having TypeTuple expressed as LLVM struct types would make much more sense and open the door to tuple lvalues.
31 lines
584 B
D
31 lines
584 B
D
module foo;
|
|
|
|
template ParameterTupleOf( Fn )
|
|
{
|
|
static if( is( Fn Params == function ) )
|
|
alias Params ParameterTupleOf;
|
|
else static if( is( Fn Params == delegate ) )
|
|
alias ParameterTupleOf!(Params) ParameterTupleOf;
|
|
else static if( is( Fn Params == Params* ) )
|
|
alias ParameterTupleOf!(Params) ParameterTupleOf;
|
|
else
|
|
static assert( false, "Argument has no parameters." );
|
|
}
|
|
|
|
struct S
|
|
{
|
|
int opApply(T)(T dg)
|
|
{
|
|
alias ParameterTupleOf!(T) U;
|
|
U u;
|
|
u[0] = 1;
|
|
u[1] = 2;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
void main()
|
|
{
|
|
foreach(int x, int y; S()){}
|
|
}
|