diff --git a/std/algorithm.d b/std/algorithm.d index 41618feda..3a80532ac 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -12996,11 +12996,12 @@ auto cartesianProduct(RR...)(RR ranges) { RR ranges; RR current; - bool empty = false; + bool empty = true; this(RR _ranges) { ranges = _ranges; + empty = false; foreach (i, r; ranges) { current[i] = r.save; @@ -13058,6 +13059,14 @@ unittest 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 auto cartesianProduct(R1, R2, RR...)(R1 range1, R2 range2, RR otherRanges) if (!allSatisfy!(isForwardRange, R1, R2, RR) ||