Home » C++ algorithm is_permutation() function

C++ algorithm is_permutation() function

by Online Tutorials Library

C++ Algorithm Functions is_permutation()

C++ Algorithm is_permutation() function compares the elements in both the containers and returns a true value if all the elements in both the containers are found to be matching even if in different order. The first range is from [first1, last1) and the second starts from first2.

Syntax

Parameter

first1: It is an input iterator to the first element of the [first1, last1).

last1: It is an input iterator to the last element of the [first1, last1).

first2: It is an input iterator to the first element of the [first2, last2).

pred: It is a binary function that accepts two elements as arguments and performs the task designed by the function.

Return value

The function returns the value true if all the elements in both the containers match even if in different order, otherwise it returns false.

Example

Output:

a and b have same elements.  

Complexity

The function has linear complexity from the first1 element to the last1 element.

Data races

Objects in both ranges are accessed.

Exceptions

The function throws an exception if any of the argument throws one.

You may also like