std::is_partitioned — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Déclaré dans l'en-tête <algorithm> |
||
|
|
(depuis C++11) | |
Retours true si tous les éléments de la gamme [first, last) qui satisfont le prédicat p présenter à tous des éléments qui n'en ont pas. Renvoie également true si [first, last) est vide .
Original:
Returns true if all elements in the range [first, last) that satisfy the predicate p appear before all elements that don't. Also returns true if [first, last) is empty.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Paramètres
| first, last | - | la plage d'éléments à vérifier Original: the range of elements to check The text has been machine-translated via Google Translate. |
| p | - | prédicat unéaire qui retourne true pour les éléments de se trouver dans le début de la plage Original: for the elements expected to be found in the beginning of the range The text has been machine-translated via Google Translate. L'expression |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
Retourne la valeur
true si le [first, last) plage est vide ou est partitionné par p. false autrement .
Original:
true if the range [first, last) is empty or is partitioned by p. false otherwise.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Complexité
À la plupart des applications std::distance(first, last) de p .
Original:
At most std::distance(first, last) applications of p.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Mise en œuvre possible
template< class InputIt, class UnaryPredicate > bool is_partitioned(InputIt first, InputIt last, UnaryPredicate p) { for (; first != last; ++first) if (!p(*first)) break; for (; first != last; ++first) if (p(*first)) return false; return true; }
Exemple
#include <algorithm> #include <array> #include <iostream> int main() { std::array<int, 9> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto is_even = [](int i){ return i % 2 == 0; }; std::cout.setf(std::ios_base::boolalpha); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::partition(v.begin(), v.end(), is_even); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::reverse(v.begin(), v.end()); std::cout << std::is_partitioned(v.begin(), v.end(), is_even); }
Résultat :
Voir aussi
divise une série d'éléments en deux groupes Original: divides a range of elements into two groups The text has been machine-translated via Google Translate. (fonction générique) [edit] | |
Pour localiser le point de partage d'une gamme partitionné Original: locates the partition point of a partitioned range The text has been machine-translated via Google Translate. (fonction générique) [edit] | |