SetDifference

Lazily computes the difference of r1 and r2. The two ranges are assumed to be sorted by less. The element types of the two ranges must have a common type.

More...
  1. struct SetDifference(alias less = "a < b", R1, R2)
  2. SetDifference!(less, R1, R2) setDifference(R1 r1, R2 r2)

Constructors

this
this(R1 r1, R2 r2)

Members

Functions

popFront
void popFront()

Properties

empty
bool empty [@property getter]
front
auto ref front [@property getter]
save
typeof(this) save [@property getter]

Return Value

A range of the difference of r1 and r2.

Detailed Description

In the case of multisets, considering that element a appears x times in r1 and y times and r2, the number of occurences of a in the resulting range is going to be x-y if x > y or 0 otherwise.

Examples

1 import std.algorithm.comparison : equal;
2 import std.range.primitives : isForwardRange;
3 
4 //sets
5 int[] a = [ 1, 2, 4, 5, 7, 9 ];
6 int[] b = [ 0, 1, 2, 4, 7, 8 ];
7 assert(equal(setDifference(a, b), [5, 9]));
8 static assert(isForwardRange!(typeof(setDifference(a, b))));
9 
10 // multisets
11 int[] x = [1, 1, 1, 2, 3];
12 int[] y = [1, 1, 2, 4, 5];
13 auto r = setDifference(x, y);
14 assert(equal(r, [1, 3]));
15 assert(setDifference(r, x).empty);

See Also

Meta

Suggestion Box / Bug Report