unique

Returns a version of the input array with only unique elements.

If the input array's length is 0 or 1 then it is immediately returned as an optimization.

@safe
T[]
unique
(
T
)
(
T[] array
)

Parameters

array T[]

the input array

Return Value

Type: T[]

an array with only unique elements

Examples

Tests out using the uniqueness method

// Empty or 1 elem should not re-allocate
int[] vals = [];
int[] newVals = unique(vals);
assert(vals.ptr == newVals.ptr);

vals = [1];
newVals = unique(vals);
assert(vals.ptr == newVals.ptr);

// Copy triggering cases
vals = [1,1];
newVals = unique(vals);
assert(newVals == [1]);

Meta