tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
stable_partition.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_STABLE_PARTITION_HPP
4#define TETL_ALGORITHM_STABLE_PARTITION_HPP
5
7
8namespace etl {
9
15template <typename BidirIt, typename Predicate>
16constexpr auto stable_partition(BidirIt f, BidirIt l, Predicate p) -> BidirIt
17{
18 auto const n = l - f;
19 if (n == 0) {
20 return f;
21 }
22 if (n == 1) {
23 return f + p(*f);
24 }
25 auto const m = f + (n / 2);
26 return etl::rotate(etl::stable_partition(f, m, p), m, etl::stable_partition(m, l, p));
27}
28
29} // namespace etl
30
31#endif // TETL_ALGORITHM_STABLE_PARTITION_HPP
constexpr auto stable_partition(BidirIt f, BidirIt l, Predicate p) -> BidirIt
Reorders the elements in the range [first, last) in such a way that all elements for which the predic...
Definition stable_partition.hpp:16
constexpr auto rotate(ForwardIt first, ForwardIt nFirst, ForwardIt last) -> ForwardIt
Performs a left rotation on a range of elements.
Definition rotate.hpp:17
Definition adjacent_find.hpp:8