tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
partition.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_PARTITION_HPP
4#define TETL_ALGORITHM_PARTITION_HPP
5
9
10namespace etl {
11
17template <typename ForwardIt, typename Predicate>
18constexpr auto partition(ForwardIt first, ForwardIt last, Predicate p) -> ForwardIt
19{
20 first = etl::find_if_not(first, last, p);
21 if (first == last) {
22 return first;
23 }
24
25 for (ForwardIt i = etl::next(first); i != last; ++i) {
26 if (p(*i)) {
27 etl::iter_swap(i, first);
28 ++first;
29 }
30 }
31 return first;
32}
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_PARTITION_HPP
constexpr auto partition(ForwardIt first, ForwardIt last, Predicate p) -> ForwardIt
Reorders the elements in the range [first, last) in such a way that all elements for which the predic...
Definition partition.hpp:18
constexpr auto iter_swap(ForwardIt1 a, ForwardIt2 b) -> void
Swaps the values of the elements the given iterators are pointing to.
Definition iter_swap.hpp:19
constexpr auto find_if_not(InputIt first, InputIt last, Predicate pred) noexcept -> InputIt
Searches for an element for which predicate q returns false.
Definition find_if_not.hpp:18
constexpr auto next(InputIt it, typename iterator_traits< InputIt >::difference_type n=1) -> InputIt
Return the nth successor of iterator it.
Definition next.hpp:14
Definition adjacent_find.hpp:8