![]() |
VOOZH | about |
In C++, the STL function std::is_permutation checks whether one sequence is a permutation of another, i.e., whether both sequences contain the same elements in any order. It uses the == operator (or a custom predicate) for comparison. This function was introduced in C++11.
B is a permutation of A
Explanation: All elements in A exist in B in any order, so the function returns true.
Basic Version (C++11)
template <class ForwardIterator1, class ForwardIterator2>
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
With Binary Predicate (C++11)
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, BinaryPredicate p);
Range-Specified Version (C++14)
template <class ForwardIterator1, class ForwardIterator2>
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2);
Range + Predicate (C++14)
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
bool is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate p);
Note: Only the number of elements in [first1, last1] is considered. If the second sequence is shorter, the behavior is undefined.
Example : Strings (Anagram Check)
Anagrams
Explanation: All letters in A appear in B, confirming that the strings are anagrams.