Skip to content

Commit

Permalink
Fix Issue 20943 - std.algorithm.setops.cartesianProduct fails for ran…
Browse files Browse the repository at this point in the history
…ges with @System popFront
  • Loading branch information
John-Colvin committed Jun 17, 2020
1 parent a6caa89 commit e33db34
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion std/algorithm/setops.d
Expand Up @@ -391,7 +391,7 @@ if (ranges.length >= 2 &&
return mixin(algoFormat("tuple(%(current[%d].front%|,%))",
iota(0, current.length)));
}
void popFront() scope @safe
void popFront() scope
{
foreach_reverse (i, ref r; current)
{
Expand Down Expand Up @@ -554,6 +554,40 @@ pure @safe nothrow @nogc unittest
foreach (pair; cartesianProduct(seq, seq)) {}
}

unittest
{
import std.algorithm.comparison : equal;
import std.typecons : tuple;

static struct SystemRange
{
int[] data;

int front() @system @property
{
return data[0];
}

bool empty() @system @property
{
return data.length == 0;
}

void popFront() @system
{
data = data[1 .. $];
}

SystemRange save() @system
{
return this;
}
}

assert(SystemRange([1, 2]).cartesianProduct(SystemRange([3, 4]))
.equal([tuple(1, 3), tuple(1, 4), tuple(2, 3), tuple(2, 4)]));
}

// largestPartialIntersection
/**
Given a range of sorted $(REF_ALTTEXT forward ranges, isForwardRange, std,range,primitives)
Expand Down

0 comments on commit e33db34

Please sign in to comment.