partition3

Rearranges elements in r in three adjacent ranges and returns them.

The first and leftmost range only contains elements in r less than pivot. The second and middle range only contains elements in r that are equal to pivot. Finally, the third and rightmost range only contains elements in r that are greater than pivot. The less-than test is defined by the binary function less.

partition3
(
alias less = "a < b"
Range
E
)
(
Range r
,)
if (
is(typeof(binaryFun!less(r.front, pivot)) == bool)
&&
is(typeof(binaryFun!less(pivot, r.front)) == bool)
&&
is(typeof(binaryFun!less(r.front, r.front)) == bool)
)

Parameters

less

The predicate to use for the rearrangement.

ss

The swapping strategy to use.

r Range

The random-access range to rearrange.

pivot E

The pivot element.

Return Value

Type: auto

A std.typecons.Tuple of the three resulting ranges. These ranges are slices of the original range.

Bugs

stable partition3 has not been implemented yet.

Examples

auto a = [ 8, 3, 4, 1, 4, 7, 4 ];
auto pieces = partition3(a, 4);
assert(pieces[0] == [ 1, 3 ]);
assert(pieces[1] == [ 4, 4, 4 ]);
assert(pieces[2] == [ 8, 7 ]);

Meta