Search
View source code
Display the source code in std/algorithm/setops.d from which this page was generated on github.
Report a bug
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

`std.algorithm.setops.SetDifference/setDifference` - multiple declarations

Function 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.

``` SetDifference!(less,R1,R2) setDifference(alias less, R1, R2) (   R1 r1,   R2 r2 ); ```

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.

Parameters

NameDescription
less Predicate the given ranges are sorted by.
r1 The first range.
r2 The range to subtract from `r1`.

Returns

A range of the difference of `r1` and `r2`.

`setSymmetricDifference`

Example

``````import std.algorithm.comparison : equal;
import std.range.primitives : isForwardRange;

//sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
assert(equal(setDifference(a, b), [5, 9]));
static assert(isForwardRange!(typeof(setDifference(a, b))));

// multisets
int[] x = [1, 1, 1, 2, 3];
int[] y = [1, 1, 2, 4, 5];
auto r = setDifference(x, y);
assert(equal(r, [1, 3]));
assert(setDifference(r, x).empty);
``````

Struct 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.

``` struct SetDifference(alias less, R1, R2)    if (isInputRange!R1 && isInputRange!R2); ```

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.

Constructors

NameDescription
`this` (r1, r2)

Properties

NameTypeDescription
`empty`[get] `bool`
`front`[get] `auto`
`save`[get] `typeof(this)`

Methods

NameDescription
`popFront` ()

Parameters

NameDescription
less Predicate the given ranges are sorted by.
r1 The first range.
r2 The range to subtract from `r1`.

Returns

A range of the difference of `r1` and `r2`.

`setSymmetricDifference`

Example

``````import std.algorithm.comparison : equal;
import std.range.primitives : isForwardRange;

//sets
int[] a = [ 1, 2, 4, 5, 7, 9 ];
int[] b = [ 0, 1, 2, 4, 7, 8 ];
assert(equal(setDifference(a, b), [5, 9]));
static assert(isForwardRange!(typeof(setDifference(a, b))));

// multisets
int[] x = [1, 1, 1, 2, 3];
int[] y = [1, 1, 2, 4, 5];
auto r = setDifference(x, y);
assert(equal(r, [1, 3]));
assert(setDifference(r, x).empty);
``````