Hi, all. So I'm trying to make some very ugly code generic. The main ugliness isn't in the code shape, it's in the running time. It's O(n^m) Eww! (don't worry, n is only about 6.)

Anyhoo, Here's what I want:

void foo(int size)(int[] arr){
    mixin(forStart!(size));
        doStuff(pos0, pos1, pos2,...); // this line is generated by another mixin that works correctly.
}

//Generates for loop headers.
private static string forStart( int sz)(){
    string forStrings = "";
    for(int i = 0; i < sz; i++){
        forStrings ~="foreach(pos"~text(i)~"; 0..arr.length)\n ";
    }
    return forStrings;
}

It is my great displeasure to report:
src\hw06.d(35): found 'EOF' instead of statement
src\hw06.d(18): Error: template instance hw06.tryCombinations!(5) error instantiating

But here's the wacky part:
I can execute this function and print it to stdout. If I do, I get...
foreach(pos0; 0..arr.length)
foreach(pos1; 0..arr.length)
foreach(pos2; 0..arr.length)
foreach(pos3; 0..arr.length)
foreach(pos4; 0..arr.length)

and I can copy-paste this exact code into where I currently have the mixin, and the code behaves correctly.

Is there some subtle aspect of mixin that I'm missing here?

Cheers,
Charles.