]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 <boost/range/begin.hpp> | |
16 | #include <boost/range/end.hpp> | |
17 | ||
18 | namespace boost { namespace algorithm { | |
19 | ||
20 | /// \fn none_of ( InputIterator first, InputIterator last, Predicate p ) | |
21 | /// \return true if none of the elements in [first, last) satisfy the predicate 'p' | |
22 | /// \note returns true on an empty range | |
23 | /// | |
24 | /// \param first The start of the input sequence | |
25 | /// \param last One past the end of the input sequence | |
26 | /// \param p A predicate for testing the elements of the sequence | |
27 | /// | |
28 | template<typename InputIterator, typename Predicate> | |
29 | bool none_of ( InputIterator first, InputIterator last, Predicate p ) | |
30 | { | |
31 | for ( ; first != last; ++first ) | |
32 | if ( p(*first)) | |
33 | return false; | |
34 | return true; | |
35 | } | |
36 | ||
37 | /// \fn none_of ( const Range &r, Predicate p ) | |
38 | /// \return true if none of the elements in the range satisfy the predicate 'p' | |
39 | /// \note returns true on an empty range | |
40 | /// | |
41 | /// \param r The input range | |
42 | /// \param p A predicate for testing the elements of the range | |
43 | /// | |
44 | template<typename Range, typename Predicate> | |
45 | bool none_of ( const Range &r, Predicate p ) | |
46 | { | |
47 | return boost::algorithm::none_of (boost::begin (r), boost::end (r), p ); | |
48 | } | |
49 | ||
50 | /// \fn none_of_equal ( InputIterator first, InputIterator last, const V &val ) | |
51 | /// \return true if none of the elements in [first, last) are equal to 'val' | |
52 | /// \note returns true on an empty range | |
53 | /// | |
54 | /// \param first The start of the input sequence | |
55 | /// \param last One past the end of the input sequence | |
56 | /// \param val A value to compare against | |
57 | /// | |
58 | template<typename InputIterator, typename V> | |
59 | bool none_of_equal ( InputIterator first, InputIterator last, const V &val ) | |
60 | { | |
61 | for ( ; first != last; ++first ) | |
62 | if ( val == *first ) | |
63 | return false; | |
64 | return true; | |
65 | } | |
66 | ||
67 | /// \fn none_of_equal ( const Range &r, const V &val ) | |
68 | /// \return true if none of the elements in the range are equal to 'val' | |
69 | /// \note returns true on an empty range | |
70 | /// | |
71 | /// \param r The input range | |
72 | /// \param val A value to compare against | |
73 | /// | |
74 | template<typename Range, typename V> | |
75 | bool none_of_equal ( const Range &r, const V & val ) | |
76 | { | |
77 | return boost::algorithm::none_of_equal (boost::begin (r), boost::end (r), val); | |
78 | } | |
79 | ||
80 | }} // namespace boost and algorithm | |
81 | ||
82 | #endif // BOOST_ALGORITHM_NONE_OF_HPP |