Return type: returns an iterator indicating the point of partition.
Working: The function partition_point() takes in 3 parameters, start position and end position iterators of the container and
a predicate function which returns a boolean value (true or false).The function traverses the container from first
position to last, up till the point where the first value for which the predicate return value is false is encountered
Once encountered, iterator pointing to that location is returned.
Container used here:- std::multiset. Multisets are associative containers that can have multiple elements with same values.
Implementation:
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
bool isUpperCase(char ch)
{
if(isupper(ch))
return true;
return false;
}
int main(int argc, char const *argv[])
{
multiset<char> arr{'A', 'B', 'C', 'D', 'e', 'f', 'g', 'h'};
multiset<char> :: iterator it = partition_point(arr.begin(), arr.end(), isUpperCase);
cout<<"UpperCase letters:"<<endl;
for(auto beg = arr.begin() ; beg != it ; beg++)
cout<<*beg<<" ";
cout<<endl;
cout<<"LowerCase letters:"<<endl;
for(auto beg = it ; beg != arr.end() ; beg++)
cout<<*beg<<" ";
cout<<endl;
return 0;
}
Sample Output:
gs_katti@gsk-47534B:~/Desktop/CppSecret/algorithm_header$ ./a.out
UpperCase letters:
A B C D
LowerCase letters:
e f g h
Comments