algorithm - STL C++

none_of()

Declaration

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

Description

This function returns true if none of the elements in range from "xFirst" up through the one before "xLast" returns true when they are passed into the function "xTest." Otherwise, the function returns false.

Header Include

#include <algorithm>

Example

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

bool IsX(char cChar) {
	return (cChar == 'X');
}

bool IsZ(char cChar) {
	return (cChar == 'Z');
}

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

	// Check for X and Z
	bool bNoneAre = none_of(qV.begin(), qV.end(), IsX);
	cout << "There " << (bNoneAre ? "is not" : "is")
		<< " an X in the vector." << endl;
	bNoneAre = none_of(qV.begin(), qV.end(), IsZ);
	cout << "There " << (bNoneAre ? "is not" : "is")
		<< " a Z in the vector." << endl;

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

Output

none_of() Output
 

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