![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
partition_point in C++
In this tutorial, we will be discussing a program to understand partition_point in C++.
Partition point is a method which returns an iterator pointing to the first value in a given range. The range is a partitioned one in which the predicate is not true.
Example
#include <iostream> #include <algorithm> #include <vector> bool IsOdd(int i) { return (i % 2) == 1; } int main(){ std::vector<int> data{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector<int> odd, even; std::stable_partition(data.begin(), data.end(), IsOdd); auto it = std::partition_point(data.begin(), data.end(), IsOdd); odd.assign(data.begin(), it); even.assign(it, data.end()); std::cout << "odd:"; for (int& x : odd) std::cout << ' ' << x; std::cout << '\n'; std::cout << "even:"; for (int& x : even) std::cout << ' ' << x; std::cout << '\n'; return 0; }
Output
odd: 1 3 5 7 9 even: 2 4 6 8 10
Advertisements