MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
partition.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_ALGORITHM_PARTITION_HPP__
2#define MSTL_CORE_ALGORITHM_PARTITION_HPP__
3
11
14
20
39template <typename Iterator, typename Predicate, enable_if_t<is_ranges_bid_iter_v<Iterator>, int> = 0>
40constexpr Iterator partition(Iterator first, Iterator last, Predicate pred) {
41 while (true) {
42 while (true) {
43 if (first == last) return first;
44
45 if (pred(*first)) ++first;
46 else break;
47 }
48 --last;
49 while (true) {
50 if (first == last) return first;
51
52 if (!pred(*last)) --last;
53 else break;
54 }
55 _MSTL iter_swap(first, last);
56 ++first;
57 }
58}
59
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;
86 --last;
87 while (comp(pivot, *last)) --last;
88 if (!(first < last)) break;
89 _MSTL iter_swap(first, last);
90 ++first;
91 }
92 return first;
93}
94
104template <typename Iterator, typename T>
105constexpr Iterator lomuto_partition(Iterator first, Iterator last, const T& pivot) {
106 return _MSTL lomuto_partition(first, last, pivot);
107}
108 // PartitionAlgorithms
110
112#endif // MSTL_CORE_ALGORITHM_PARTITION_HPP__
#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)))
交换迭代器指向的元素
MSTL移位和修改算法