product res if length length swap foreach foreach res return res

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
T[][] product(T)([T] a, [T] b){
T[][] res;
if (a.length >= b.length){
swap(a,b);
}
foreach(e; b){
foreach(i; a){
res~=[e,i];
}
}
return res;
}