Use new cartesianProduct implementation for 2-argument case as well.

The original implementation will now only be used when one or both the
ranges is either non-forward or infinite. The new implementation is also
more attribute-friendly (works with pure, nothrow, @nogc, @safe), so
this also fixes issue 13091.
This commit is contained in:
H. S. Teoh 2014-09-18 17:43:09 -07:00
parent 0fb1bee92d
commit 556ef61ef8

View file

@ -13308,6 +13308,8 @@ When there are more than two ranges, the above conditions apply to each
adjacent pair of ranges.
*/
auto cartesianProduct(R1, R2)(R1 range1, R2 range2)
if (!allSatisfy!(isForwardRange, R1, R2) ||
anySatisfy!(isInfinite, R1, R2))
{
static if (isInfinite!R1 && isInfinite!R2)
{
@ -13536,9 +13538,17 @@ unittest
}
}
// Issue 13091
pure nothrow @safe @nogc unittest
{
import std.algorithm: cartesianProduct;
int[1] a = [1];
foreach (t; cartesianProduct(a[], a[])) {}
}
/// ditto
auto cartesianProduct(RR...)(RR ranges)
if (ranges.length > 2 &&
if (ranges.length >= 2 &&
allSatisfy!(isForwardRange, RR) &&
!anySatisfy!(isInfinite, RR))
{