std.algorithm.setops.set_union
- multiple declarations
- Function setUnion
- Struct SetUnion
Function setUnion
Lazily computes the union of two or more ranges
. The ranges
are assumed to be sorted by rs
less
. Elements in the output are not
unique; the length of the output is the sum of the lengths of the
inputs. (The length
member is offered if all ranges also have
length.) The element types of all ranges must have a common type.
Prototype
SetUnion!(less,Rs) setUnion(alias less, Rs...)( Rs rs );
Parameters
Name | Description |
---|---|
less | Predicate the given ranges are sorted by. |
rs | The ranges to compute the union for. |
Returns
A range containing the union of the given ranges.
Example
import std.algorithm.comparison : equal; int[] a = [ 1, 2, 4, 5, 7, 9 ]; int[] b = [ 0, 1, 2, 4, 7, 8 ]; double[] c = [ 10.5 ]; static assert(isForwardRange!(typeof(setUnion(a, b)))); assert(setUnion(a, b).length == a.length + b.length); assert(equal(setUnion(a, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9][])); assert(equal(setUnion(a, c, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9, 10.5][])); auto u = setUnion(a, b); u.front--; assert(equal(u, [-1, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9][]));
Struct SetUnion
Lazily computes the union of two or more ranges rs
. The ranges
are assumed to be sorted by less
. Elements in the output are not
unique; the length of the output is the sum of the lengths of the
inputs. (The length
member is offered if all ranges also have
length.) The element types of all ranges must have a common type.
Parameters
Name | Description |
---|---|
less | Predicate the given ranges are sorted by. |
rs | The ranges to compute the union for. |
Returns
A range containing the union of the given ranges.
Example
import std.algorithm.comparison : equal; int[] a = [ 1, 2, 4, 5, 7, 9 ]; int[] b = [ 0, 1, 2, 4, 7, 8 ]; double[] c = [ 10.5 ]; static assert(isForwardRange!(typeof(setUnion(a, b)))); assert(setUnion(a, b).length == a.length + b.length); assert(equal(setUnion(a, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9][])); assert(equal(setUnion(a, c, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9, 10.5][])); auto u = setUnion(a, b); u.front--; assert(equal(u, [-1, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9][]));