◐ Shell
clean mode source ↗

std::is_partitioned - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<algorithm>

template< class InputIt, class UnaryPredicate > bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );

(dal C++11)

Restituisce true se tutti gli elementi della [first, last) intervallo che soddisfano il predicato p dinanzi a tutti gli elementi che non lo fanno. Anche se restituisce true [first, last) è vuoto.

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.

Parametri

first, last -

la gamma di elementi da controllare

Original:

the range of elements to check

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

p - unary predicate which returns ​true

per gli elementi prevedibile la presenza all'inizio della gamma

Original:

for the elements expected to be found in the beginning of the range

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

.

The signature of the predicate function should be equivalent to the following:

bool pred(const Type &a);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The type Type must be such that an object of type InputIt can be dereferenced and then implicitly converted to Type. ​

Type requirements
-InputIt must meet the requirements of InputIterator.

Valore di ritorno

true se il [first, last) campo è vuoto o è partizionato da p. false altrimenti.

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.

Complessità

Alla maggior parte delle applicazioni di std::distance(first, last) 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.

Possibile implementazione

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;
}

Esempio

#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);
}

Output:

Vedi anche

divide una serie di elementi in due gruppi

Original:

divides a range of elements into two groups

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(funzione di modello) [modifica]
locates the partition point of a partitioned range
(funzione di modello) [modifica]