View source code
Display the source code in std/algorithm/sorting.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
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.

Function std.algorithm.sorting.partition3

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

auto partition3(alias less, SwapStrategy ss = SwapStrategy.unstable, Range, E) (
  Range r,
  E pivot
)
if (ss == SwapStrategy.unstable && isRandomAccessRange!Range && hasSwappableElements!Range && hasLength!Range && hasSlicing!Range && 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));

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.

Parameters

NameDescription
less The predicate to use for the rearrangement.
ss The swapping strategy to use.
r The random-access range to rearrange.
pivot The pivot element.

Returns

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

BUGS

stable partition3 has not been implemented yet.

Example

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

Authors

Andrei Alexandrescu

License

Boost License 1.0.