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