命名空间
变体
操作

std::experimental::ranges::is_permutation

来自 cppreference.cn
< cpp‎ | experimental‎ | ranges
 
 
实验性
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行性扩展 (parallelism TS)
并行性扩展 2 (parallelism TS v2)
并发性扩展 (concurrency TS)
并发性扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions TR)
实验性非 TS
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
 
template< ForwardIterator I1, Sentinel<I1> S1, ForwardIterator I2, Sentinel<I2> S2,

          class Pred = ranges::equal_to<>,
          class Proj1 = ranges::identity, class Proj2 = ranges::identity >
    requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>
bool is_permutation( I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{},

                     Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} );
(1) (ranges TS)
template< ForwardRange R1, ForwardRange R2, class Pred = ranges::equal_to<>,

          class Proj1 = ranges::identity, class Proj2 = ranges::identity >
    requires IndirectlyComparable<ranges::iterator_t<R1>, ranges::iterator_t<R2>,
                                  Pred, Proj1, Proj2>
bool is_permutation( R1&& r1, R2&& r2, Pred pred = Pred{},

                     Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} );
(2) (ranges TS)
template< ForwardIterator I1, Sentinel<I1> S1, class I2,

          class Pred = ranges::equal_to<>,
          class Proj1 = ranges::identity, class Proj2 = ranges::identity >
    requires ForwardIterator<std::decay_t<I2>> && !Range<I2> &&
             IndirectlyComparable<I1, std::decay_t<I2>, Pred, Proj1, Proj2>
bool is_permutation( I1 first1, S1 last1, I2&& first2_, Pred pred = Pred{},

                     Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} );
(3) (ranges TS)
(已弃用)
template< ForwardRange R1, class I2, class Pred = ranges::equal_to<>,

          class Proj1 = ranges::identity, class Proj2 = ranges::identity >
    requires ForwardIterator<std::decay_t<I2>> && !Range<I2> &&
             IndirectlyComparable<ranges::iterator_t<R1>, std::decay_t<I2>, Pred, Proj1, Proj2>
bool is_permutation( R1&& r1, I2&& first2_, Pred pred = Pred{},

                     Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{} );
(4) (ranges TS)
(已弃用)
1) 如果存在一个范围 [first1last1) 中元素的排列,使得该范围等于 [first2last2),则返回 true,否则返回 false
2)(1) 相同,但使用 r1 作为第一个源范围,r2 作为第二个源范围,如同使用 ranges::begin(r1) 作为 first1ranges::end(r1) 作为 last1ranges::begin(r2) 作为 first2,以及 ranges::end(r2) 作为 last2
3)(1) 相同,除了 first2 定义为如同 std::decay_t<I2> first2 = std::forward<I2>(first2_);,而 last2first2 + (last1 - first1)
4)(3) 相同,但使用 r1 作为第一个源范围,如同使用 ranges::begin(r1) 作为 first1ranges::end(r1) 作为 last1

如果两个范围具有相同数量的元素,并且对于范围 [first1last1) 中的每个迭代器 iranges::invoke(pred, ranges::invoke(proj1, *i), ranges::invoke(proj2, *(first2 + (i - first1))))true,则认为这两个范围相等。

尽管上面描述了声明,但算法声明的模板参数的实际数量和顺序是未指定的。因此,如果在调用算法时使用显式模板参数,则程序可能不具备可移植性。

目录

[编辑] 参数

first1, last1 - 元素的第一个范围
r1 - 元素的第一个范围
first2, last2 - 元素的第二个范围
r2 - 元素的第二个范围
first2_ - 元素第二个范围的起始
pred - 应用于投影元素的谓词
proj1 - 应用于第一个范围中元素的投影
proj2 - 应用于第二个范围中元素的投影

[编辑] 返回值

如果范围 [first1last1) 是范围 [first2last2) 的排列,则返回 true

[编辑] 复杂度

谓词和每个投影最多应用 O(N2) 次,或者如果序列已经相等,则恰好应用 N 次,其中 N = last1 - first1

然而,如果满足 SizedSentinel<S1, I1> && SizedSentinel<S2, I2>last1 - first1 != last2 - first2,则不应用谓词和投影。

[编辑] 示例

[编辑] 参见

确定一个序列是否是另一个序列的排列
(函数模板) [编辑]
生成一个范围的元素的下一个更大的字典序排列
(函数模板) [编辑]
生成一个范围的元素的下一个更小的字典序排列
(函数模板) [编辑]