std::is_permutation
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <algorithm> | ||
template<class ForwardIt1, class ForwardIt2 > bool is_permutation( ForwardIt1 first, ForwardIt1 last, | (1) | (depuis C++11) |
template<class ForwardIt1, class ForwardIt2, class BinaryPredicate > bool is_permutation( ForwardIt1 first, ForwardIt1 last, | (2) | (depuis C++11) |
[first1, last1)
qui rend cet intervalle égal à l'intervalle commençant à d_first
. La première version utilise operator==
pour l'égalité, la deuxième version utilise le p
prédicat binaire[first1, last1)
that makes that range equal to the range beginning at d_first
. The first version uses operator==
for equality, the second version uses the binary predicate p
You can help to correct and verify the translation. Click here for instructions.
Sommaire |
[modifier]Paramètres
first, last | - | la plage d'éléments à comparer Original: the range of elements to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
d_first | - | le début de la deuxième plage de comparer Original: the beginning of the second range to compare The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
p | - | binary predicate which returns true if the elements should be treated as equal. The signature of the predicate function should be equivalent to the following: bool pred(const Type1 &a, const Type2 &b); The signature does not need to have const&, but the function must not modify the objects passed to it. |
Type requirements | ||
-ForwardIt1, ForwardIt2 must meet the requirements of ForwardIterator . |
[modifier]Retourne la valeur
[first, last)
plage est une permutation de la gamme débutant à d_first
.[first, last)
is a permutation of the range beginning at d_first
.You can help to correct and verify the translation. Click here for instructions.
[modifier]Complexité
You can help to correct and verify the translation. Click here for instructions.
[modifier]Mise en œuvre possible
template<class ForwardIt1, class ForwardIt2>bool is_permutation(ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first){// skip common prefixstd::tie(first, d_first)=std::mismatch(first, last, d_first);// iterate over the rest, counting how many times each element// from [first, last) appears in [d_first, d_last)if(first != last){ ForwardIt2 d_last = d_first;std::advance(d_last, std::distance(first, last));for(ForwardIt1 i = first; i != last;++i){if(i !=std::find(first, i, *i))continue;// already counted this *i auto m =std::count(d_first, d_last, *i);if(m==0||std::count(i, last, *i)!= m){returnfalse;}}}returntrue;} |
[modifier]Exemple
#include <algorithm>#include <vector>#include <iostream>int main(){std::vector<int> v1{1,2,3,4,5};std::vector<int> v2{3,5,4,1,2};std::cout<<"3,5,4,1,2 is a permutation of 1,2,3,4,5? "<<std::boolalpha<< std::is_permutation(v1.begin(), v1.end(), v2.begin())<<'\n'; std::vector<int> v3{3,5,4,1,1};std::cout<<"3,5,4,1,1 is a permutation of 1,2,3,4,5? "<<std::boolalpha<< std::is_permutation(v1.begin(), v1.end(), v3.begin())<<'\n';}
Résultat :
3,5,4,1,2 is a permutation of 1,2,3,4,5? true 3,5,4,1,1 is a permutation of 1,2,3,4,5? false
[modifier]Voir aussi
génère la plus grande lexicographique prochaine permutation d'un ensemble d'éléments Original: generates the next greater lexicographic permutation of a range of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) | |
lexicographique génère le plus petit côté d'une permutation série d'éléments Original: generates the next smaller lexicographic permutation of a range of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) |