On Sunday, 26 January 2014 at 21:49:37 UTC, matovitch wrote:
void main() {
immutable int[] B = [ 1, 2, 3 ];
immutable int[] C = [ 4, 5, 6 ];
auto BC = zip(B, C);
writeln(BC);
}
Here B and C aren't inputRange thought acording to the template
constraint of zip there should be. How can it compiles ?
B and C aren't, but B[] and C[] are. That's what's going on when
you pass an array as function argument: a full slice is taken.
See for yourself:
void foo(R)(R r) {
writeln(R.stringof);
}
foo(B); // will print immutable(int)[]
How to compute the cartesian product of two immutable ranges ?
Short answer: with std.algorithm - you can't. Because internally
it (Zip, actually) performs assignments, and you can't assign to
immutable(T).
Why?