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