1#ifndef NEFORCE_CORE_ALGORITHM_PERMUTATION_HPP__
2#define NEFORCE_CORE_ALGORITHM_PERMUTATION_HPP__
13NEFORCE_BEGIN_NAMESPACE__
45template <
typename Iterator1,
typename Iterator2,
typename BinaryPred>
46constexpr bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, BinaryPred pred) {
48 "Iterator must be forward_iterator");
50 for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
51 if (!pred(*first1, *first2)) {
56 if (first1 == last1 && first2 == last2) {
59 if (first1 == last1 || first2 == last2) {
63 for (Iterator1 i = first1; i != last1; ++i) {
64 bool already_counted =
false;
65 for (Iterator1 j = first1; j != i; ++j) {
67 already_counted =
true;
71 if (!already_counted) {
73 for (Iterator2 j = first2; j != last2; ++j) {
84 for (++j; j != last1; ++j) {
107template <
typename Iterator1,
typename Iterator2>
108constexpr bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2) {
130template <
typename Iterator,
typename Compare>
149 while (!comp(*i, *--j)) {
169template <
typename Iterator>
192template <
typename Iterator,
typename Compare>
211 while (!comp(*--j, *i)) {
231template <
typename Iterator>
240NEFORCE_END_NAMESPACE__
constexpr bool is_ranges_bid_iter_v
检查是否为范围双向迭代器
constexpr bool is_ranges_fwd_iter_v
检查是否为范围前向迭代器
constexpr bool prev_permutation(Iterator first, Iterator last, Compare comp)
生成上一个字典序排列
constexpr bool is_permutation(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, BinaryPred pred)
检查两个序列是否为排列关系
constexpr bool next_permutation(Iterator first, Iterator last, Compare comp)
生成下一个字典序排列
constexpr void iter_swap(Iterator1 a, Iterator2 b) noexcept(noexcept(_NEFORCE swap(*a, *b)))
交换迭代器指向的元素
constexpr void reverse(Iterator first, Iterator last)
反转范围元素顺序