topNCopy

Copies the top n elements of the input range source into the random-access range target, where n = target.length.

Elements of source are not touched. If sorted is true, the target is sorted. Otherwise, the target respects the heap property.

TRange
topNCopy
(
alias less = "a < b"
SRange
TRange
)
(
SRange source
,
TRange target
,
SortOutput sorted = No.sortOutput
)
if (
isInputRange!(SRange) &&
&&
hasLength!(TRange)
&&
hasSlicing!(TRange)
)

Parameters

less

The predicate to sort by.

source SRange

The source range.

target TRange

The target range.

sorted SortOutput

Whether to sort the elements copied into target.

Return Value

Type: TRange

The slice of target containing the copied elements.

Examples

import std.typecons : Yes;

int[] a = [ 10, 16, 2, 3, 1, 5, 0 ];
int[] b = new int[3];
topNCopy(a, b, Yes.sortOutput);
assert(b == [ 0, 1, 2 ]);

Meta