algorithm - STL C++

is_partitioned()

Declaration

template <class InputIterator, class Predicate>
bool is_partitioned(
	InputIterator xFirst,
	InputIterator xLast,
	Predicate xTest
);

Description

This function tests the range of entries starting at "xFirst" up to the one before "xLast" to determine whether the set of all entries in the range that satisfy the "xTest" come before the entries that do not satisfy "xTest."

Header Include

#include <algorithm>

Example

#include <iostream>
#include <vector>
#include <algorithm>

bool NotDotNet(char cChar) {
	return ((cChar != '.') &&
		(cChar != 'n') &&
		(cChar != 'e') &&
		(cChar != 't'));
}

int main()
{
	using namespace std;

	// Create a vector instance
	vector<char> qV;
	qV.push_back('X');
	qV.push_back('o');
	qV.push_back('a');
	qV.push_back('X');
	qV.push_back('.');
	qV.push_back('n');
	qV.push_back('e');
	qV.push_back('t');

	vector<char>::iterator qIter;
	// Output the vector
	cout << "The vector: ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}

	// Partition test
	bool bIsPart = is_partitioned(qV.begin(), qV.end(), NotDotNet);
	cout << (bIsPart ? " is " : " is not ") << "partitioned." << endl;

	// Change one letter
	qV[5] = 'p';
	// Output the new vector
	cout << "The vector: ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}

	// Partition test
	bIsPart = is_partitioned(qV.begin(), qV.end(), NotDotNet);
	cout << (bIsPart ? " is " : " is not ") << "partitioned." << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

is_partitioned() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.