1#ifndef MSTL_CORE_ALGORITHM_PARTITION_HPP__
2#define MSTL_CORE_ALGORITHM_PARTITION_HPP__
39template <
typename Iterator,
typename Predicate, enable_if_t<is_ranges_b
id_iter_v<Iterator>,
int> = 0>
40constexpr Iterator
partition(Iterator first, Iterator last, Predicate pred) {
43 if (first == last)
return first;
45 if (pred(*first)) ++first;
50 if (first == last)
return first;
52 if (!pred(*last)) --last;
82template <
typename Iterator,
typename T,
typename Compare, enable_if_t<is_ranges_rnd_iter_v<Iterator>,
int> = 0>
83constexpr Iterator
lomuto_partition(Iterator first, Iterator last,
const T& pivot, Compare comp) {
84 while (first < last) {
85 while (comp(*first, pivot)) ++first;
87 while (comp(pivot, *last)) --last;
88 if (!(first < last))
break;
104template <
typename Iterator,
typename T>
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
constexpr Iterator partition(Iterator first, Iterator last, Predicate pred)
分区算法
constexpr Iterator lomuto_partition(Iterator first, Iterator last, const T &pivot, Compare comp)
Lomuto分区算法
constexpr void iter_swap(Iterator1 a, Iterator2 b) noexcept(noexcept(_MSTL swap(*a, *b)))
交换迭代器指向的元素