.init value of cartesianProduct should be empty.

This commit is contained in:
H. S. Teoh 2014-07-14 12:47:28 -07:00
parent 6e51fdf469
commit 5f0155b0c8

View file

@ -12996,11 +12996,12 @@ auto cartesianProduct(RR...)(RR ranges)
{ {
RR ranges; RR ranges;
RR current; RR current;
bool empty = false; bool empty = true;
this(RR _ranges) this(RR _ranges)
{ {
ranges = _ranges; ranges = _ranges;
empty = false;
foreach (i, r; ranges) foreach (i, r; ranges)
{ {
current[i] = r.save; current[i] = r.save;
@ -13058,6 +13059,14 @@ unittest
foreach (_; cprod2) {} // should not crash foreach (_; cprod2) {} // should not crash
} }
unittest
{
// .init value of cartesianProduct should be empty
auto cprod = cartesianProduct([0,0], [1,1], [2,2]);
assert(!cprod.empty);
assert(cprod.init.empty);
}
/// ditto /// ditto
auto cartesianProduct(R1, R2, RR...)(R1 range1, R2 range2, RR otherRanges) auto cartesianProduct(R1, R2, RR...)(R1 range1, R2 range2, RR otherRanges)
if (!allSatisfy!(isForwardRange, R1, R2, RR) || if (!allSatisfy!(isForwardRange, R1, R2, RR) ||