Chris@16
|
1 /*
|
Chris@16
|
2 Copyright (c) Marshall Clow 2008-2012.
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7
|
Chris@16
|
8 /// \file none_of.hpp
|
Chris@16
|
9 /// \brief Test ranges to see if no elements match a value or predicate.
|
Chris@16
|
10 /// \author Marshall Clow
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ALGORITHM_NONE_OF_HPP
|
Chris@16
|
13 #define BOOST_ALGORITHM_NONE_OF_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <algorithm> // for std::none_of, if available
|
Chris@16
|
16 #include <boost/range/begin.hpp>
|
Chris@16
|
17 #include <boost/range/end.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost { namespace algorithm {
|
Chris@16
|
20
|
Chris@16
|
21 /// \fn none_of ( InputIterator first, InputIterator last, Predicate p )
|
Chris@16
|
22 /// \return true if none of the elements in [first, last) satisfy the predicate 'p'
|
Chris@16
|
23 /// \note returns true on an empty range
|
Chris@16
|
24 ///
|
Chris@16
|
25 /// \param first The start of the input sequence
|
Chris@16
|
26 /// \param last One past the end of the input sequence
|
Chris@16
|
27 /// \param p A predicate for testing the elements of the sequence
|
Chris@16
|
28 ///
|
Chris@16
|
29 template<typename InputIterator, typename Predicate>
|
Chris@16
|
30 bool none_of ( InputIterator first, InputIterator last, Predicate p )
|
Chris@16
|
31 {
|
Chris@16
|
32 for ( ; first != last; ++first )
|
Chris@16
|
33 if ( p(*first))
|
Chris@16
|
34 return false;
|
Chris@16
|
35 return true;
|
Chris@16
|
36 }
|
Chris@16
|
37
|
Chris@16
|
38 /// \fn none_of ( const Range &r, Predicate p )
|
Chris@16
|
39 /// \return true if none of the elements in the range satisfy the predicate 'p'
|
Chris@16
|
40 /// \note returns true on an empty range
|
Chris@16
|
41 ///
|
Chris@16
|
42 /// \param r The input range
|
Chris@16
|
43 /// \param p A predicate for testing the elements of the range
|
Chris@16
|
44 ///
|
Chris@16
|
45 template<typename Range, typename Predicate>
|
Chris@16
|
46 bool none_of ( const Range &r, Predicate p )
|
Chris@16
|
47 {
|
Chris@16
|
48 return boost::algorithm::none_of (boost::begin (r), boost::end (r), p );
|
Chris@16
|
49 }
|
Chris@16
|
50
|
Chris@16
|
51 /// \fn none_of_equal ( InputIterator first, InputIterator last, const V &val )
|
Chris@16
|
52 /// \return true if none of the elements in [first, last) are equal to 'val'
|
Chris@16
|
53 /// \note returns true on an empty range
|
Chris@16
|
54 ///
|
Chris@16
|
55 /// \param first The start of the input sequence
|
Chris@16
|
56 /// \param last One past the end of the input sequence
|
Chris@16
|
57 /// \param val A value to compare against
|
Chris@16
|
58 ///
|
Chris@16
|
59 template<typename InputIterator, typename V>
|
Chris@16
|
60 bool none_of_equal ( InputIterator first, InputIterator last, const V &val )
|
Chris@16
|
61 {
|
Chris@16
|
62 for ( ; first != last; ++first )
|
Chris@16
|
63 if ( val == *first )
|
Chris@16
|
64 return false;
|
Chris@16
|
65 return true;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 /// \fn none_of_equal ( const Range &r, const V &val )
|
Chris@16
|
69 /// \return true if none of the elements in the range are equal to 'val'
|
Chris@16
|
70 /// \note returns true on an empty range
|
Chris@16
|
71 ///
|
Chris@16
|
72 /// \param r The input range
|
Chris@16
|
73 /// \param val A value to compare against
|
Chris@16
|
74 ///
|
Chris@16
|
75 template<typename Range, typename V>
|
Chris@16
|
76 bool none_of_equal ( const Range &r, const V & val )
|
Chris@16
|
77 {
|
Chris@16
|
78 return boost::algorithm::none_of_equal (boost::begin (r), boost::end (r), val);
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 }} // namespace boost and algorithm
|
Chris@16
|
82
|
Chris@16
|
83 #endif // BOOST_ALGORITHM_NONE_OF_HPP
|