Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.
PrevUpHomeNext

none_of

The header file 'boost/algorithm/cxx11/none_of.hpp' contains four variants of a single algorithm, none_of. The algorithm tests all the elements of a sequence and returns true if they none of them share a property.

The routine none_of takes a sequence and a predicate. It will return true if the predicate returns false when applied to every element in the sequence.

The routine none_of_equal takes a sequence and a value. It will return true if none of the elements in the sequence compare equal to the passed in value.

Both routines come in two forms; the first one takes two iterators to define the range. The second form takes a single range parameter, and uses Boost.Range to traverse it.

interface

The function none_of returns true if the predicate returns false for every item in the sequence. There are two versions; one takes two iterators, and the other takes a range.

namespace boost { namespace algorithm {
template<typename InputIterator, typename Predicate>
	bool none_of ( InputIterator first, InputIterator last, Predicate p );
template<typename Range, typename Predicate>
	bool none_of ( const Range &r, Predicate p );
}}

The function none_of_equal is similar to none_of, but instead of taking a predicate to test the elements of the sequence, it takes a value to compare against.

namespace boost { namespace algorithm {
template<typename InputIterator, typename V>
	bool none_of_equal ( InputIterator first, InputIterator last, V const &val );
template<typename Range, typename V>
	bool none_of_equal ( const Range &r, V const &val );
}}

Examples

Given the container c containing { 0, 1, 2, 3, 14, 15 }, then

bool isOdd ( int i ) { return i % 2 == 1; }
bool lessThan10 ( int i ) { return i < 10; }

using boost::algorithm;

none_of ( c, isOdd ) --> false
none_of ( c.begin (), c.end (), lessThan10 ) --> false
none_of ( c.begin () + 4, c.end (), lessThan10 ) --> true
none_of ( c.end (), c.end (), isOdd ) --> true  // empty range
none_of_equal ( c, 3 ) --> false
none_of_equal ( c.begin (), c.begin () + 3, 3 ) --> true
none_of_equal ( c.begin (), c.begin (), 99 ) --> true  // empty range

Iterator Requirements

none_of and none_of_equal work on all iterators except output iterators.

Complexity

All of the variants of none_of and none_of_equal run in O(N) (linear) time; that is, they compare against each element in the list once. If any of the comparisons succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence.

Exception Safety

All of the variants of none_of and none_of_equal take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee.

Notes

PrevUpHomeNext