Chris@16
|
1 /*
|
Chris@16
|
2 Copyright (c) Marshall Clow 2011-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 find_if_not.hpp
|
Chris@16
|
9 /// \brief Find the first element in a sequence that does not satisfy a predicate.
|
Chris@16
|
10 /// \author Marshall Clow
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_ALGORITHM_FIND_IF_NOT_HPP
|
Chris@16
|
13 #define BOOST_ALGORITHM_FIND_IF_NOT_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <algorithm> // for std::find_if_not, if it exists
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/range/begin.hpp>
|
Chris@16
|
18 #include <boost/range/end.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace algorithm {
|
Chris@16
|
21
|
Chris@16
|
22 /// \fn find_if_not(InputIterator first, InputIterator last, Predicate p)
|
Chris@16
|
23 /// \brief Finds the first element in the sequence that does not satisfy the predicate.
|
Chris@16
|
24 /// \return The iterator pointing to the desired element.
|
Chris@16
|
25 ///
|
Chris@16
|
26 /// \param first The start of the input sequence
|
Chris@16
|
27 /// \param last One past the end of the input sequence
|
Chris@16
|
28 /// \param p A predicate for testing the elements of the range
|
Chris@16
|
29 /// \note This function is part of the C++2011 standard library.
|
Chris@16
|
30 /// We will use the standard one if it is available,
|
Chris@16
|
31 /// otherwise we have our own implementation.
|
Chris@16
|
32 template<typename InputIterator, typename Predicate>
|
Chris@16
|
33 InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p )
|
Chris@16
|
34 {
|
Chris@16
|
35 for ( ; first != last; ++first )
|
Chris@16
|
36 if ( !p(*first))
|
Chris@16
|
37 break;
|
Chris@16
|
38 return first;
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 /// \fn find_if_not ( const Range &r, Predicate p )
|
Chris@16
|
42 /// \brief Finds the first element in the sequence that does not satisfy the predicate.
|
Chris@16
|
43 /// \return The iterator pointing to the desired element.
|
Chris@16
|
44 ///
|
Chris@16
|
45 /// \param r The input range
|
Chris@16
|
46 /// \param p A predicate for testing the elements of the range
|
Chris@16
|
47 ///
|
Chris@16
|
48 template<typename Range, typename Predicate>
|
Chris@16
|
49 typename boost::range_iterator<const Range>::type find_if_not ( const Range &r, Predicate p )
|
Chris@16
|
50 {
|
Chris@16
|
51 return boost::algorithm::find_if_not (boost::begin (r), boost::end(r), p);
|
Chris@16
|
52 }
|
Chris@16
|
53
|
Chris@16
|
54 }}
|
Chris@16
|
55 #endif // BOOST_ALGORITHM_FIND_IF_NOT_HPP
|