Josh:
Can anyone please explain why this works:
auto numbers = sequence!("n")();
auto trimmed = setDifference(setDifference(numbers,
sequence!("n * a[0]")(2)), sequence!("n * a[0]")(3));
but this doesn't?
auto numbers = sequence!("n")();
auto trimmed = setDifference(numbers, sequence!("n *
a[0]")(2));
trimmed = setDifference(trimmed, sequence!("n * a[0]")(3));
This compiles:
void main() {
import std.stdio, std.algorithm, std.range;
auto numbers = sequence!("n")();
auto trimmed = setDifference(numbers, sequence!("n *
a[0]")(2));
auto trimmed2 = setDifference(trimmed, sequence!("n *
a[0]")(3));
pragma(msg, typeof(trimmed));
pragma(msg, typeof(trimmed2));
}
Output:
SetDifference!("a < b", Sequence!("n", Tuple!()), Sequence!("n *
a[0]", Tuple!int))
SetDifference!("a < b", SetDifference!("a < b", Sequence!("n",
Tuple!()), Sequence!("n * a[0]", Tuple!int)), Sequence!("n *
a[0]", Tuple!int))
The two trimmed have different type, because in D ranges are
template-based, so often things have different type, unless they
are identical.
Bye,
bearophile