Namespaces
Variants

std::experimental::ranges:: is_permutation

From cppreference.net
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) 若存在范围 [ first1 , last1 ) 中元素的某种排列能使该范围等于 [ first2 , last2 ) ,则返回 true ;否则返回 false
2) (1) 相同,但使用 r1 作为第一源范围, r2 作为第二源范围,如同使用 ranges:: begin ( r1 ) 作为 first1 ranges:: end ( r1 ) 作为 last1 ranges:: begin ( r2 ) 作为 first2 ,以及 ranges:: end ( r2 ) 作为 last2
3) (1) 相同,区别在于 first2 的定义方式相当于 std:: decay_t < I2 > first2 = std:: forward < I2 > ( first2_ ) ; ,且 last2 等于 first2 + ( last1 - first1 )
4) (3) 相同,但使用 r1 作为第一源范围,如同使用 ranges:: begin ( r1 ) 作为 first1 ,并使用 ranges:: end ( r1 ) 作为 last1

两个范围被视为相等,当且仅当它们具有相同数量的元素,并且对于范围 [ first1 , last1 ) 中的每个迭代器 i ranges:: invoke ( pred, ranges:: invoke ( proj1, * i ) , ranges:: invoke ( proj2, * ( first2 + ( i - first1 ) ) ) ) 的结果为 true

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

目录

参数

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

返回值

当范围 [ first1 , last1 ) 是范围 [ first2 , last2 ) 的一个排列时返回 true

复杂度

最多需要 O(N 2 ) 次谓词和投影操作,若序列已相等则仅需 N 次,其中 N = last1 - first1

然而如果满足 SizedSentinel < S1, I1 > && SizedSentinel < S2, I2 > last1 - first1 ! = last2 - first2 ,则不会执行任何谓词和投影操作。

示例

参见

判断一个序列是否为另一个序列的排列
(函数模板)
生成元素范围的下一个较大字典序排列
(函数模板)
生成元素范围的下一个较小字典序排列
(函数模板)