Is_partitioned prototype:
STD: is_partitioned
template <class InputIterator, class UnaryPredicate> bool is_partitioned (InputIterator first, InputIterator last, UnaryPredicate pred);
Whether the elements in the test scope are classified based on Pred. If yes, true is returned; otherwise, false is returned.
Division means that PRED (* It) is performed on each element, and whether the values of true and false in the result are a division.
For example, t f, t, f, or f t is a division.
However, t f t or f t f is not a division.
The behavior is as follows: (this behavior seems to be a bit problematic. For example, if the division is fffttt, it seems that false is returned)
template <class InputIterator1, class InputIterator2> bool is_partitioned (InputIterator1 first, InputIterator1 last, UnaryPredicate pred){ while (first!=last && pred(*first)) { ++first; } while (first!=last) { if (pred(*first)) return false; ++first; } return true;}
A simple example:
#include <iostream>#include <vector>#include <array>#include <algorithm>using namespace std;void ispartitioned2(){ vector<int> vi{1,3,5,7,9,8,6,10,12}; cout<<"vi="; for_each(vi.begin(),vi.end(),[](int i){cout<<i<<" ";}); cout<<endl; if(is_partitioned(vi.begin(),vi.end(),[](int n){return n%2!=0;})) cout<<"v1 is a partitioned!"<<endl; else cout<<"v1 not a partitioned!"<<endl; vector<int> v2{2,4,6,8}; cout<<"v2="; for_each(v2.begin(),v2.end(),[](int i){cout<<i<<" ";}); cout<<endl; if(is_partitioned(v2.begin(),v2.end(),[](int n){return n%2!=0;})) cout<<"v2 is a partitioned!"<<endl; else cout<<"v2 not a partitioned!"<<endl; vector<int> v3{1,3,4,6,8}; cout<<"v3="; for_each(v3.begin(),v3.end(),[](int i){cout<<i<<" ";}); cout<<endl; if(is_partitioned(v3.begin(),v3.end(),[](int n){return n%2!=0;})) cout<<"v3 is a partitioned!"<<endl; else cout<<"v3 not a partitioned!"<<endl; vector<int> v4{1,2,5,4,6,8}; cout<<"v4="; for_each(v4.begin(),v4.end(),[](int i){cout<<i<<" ";}); cout<<endl; if(is_partitioned(v4.begin(),v4.end(),[](int n){return n%2!=0;})) cout<<"v4 is a partitioned!"<<endl; else cout<<"v4 not a partitioned!"<<endl;}
Run:
We can see that V3 belongs to the ffttt type, but it is still a division!
------------------------------------------------------------------
// For more instructions on writing errors or poor information, you can leave a message below or click the email address in the upper left corner to send an email to me, pointing out my errors and deficiencies, so that I can modify them, thank you for sharing it.
Reprinted please indicate the source: http://blog.csdn.net/qq844352155
Author: unparalleled
Email: [email protected]
Yu gdut
------------------------------------------------------------------
STL algorithm is_partitioned (26)