diff --git a/std/algorithm/setops.d b/std/algorithm/setops.d index b970e21ecca..fbf066242e3 100644 --- a/std/algorithm/setops.d +++ b/std/algorithm/setops.d @@ -353,6 +353,40 @@ pure nothrow @safe @nogc unittest foreach (t; cartesianProduct(a[], a[])) {} } +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)])); +} + /// ditto auto cartesianProduct(RR...)(RR ranges) if (ranges.length >= 2 &&