find_if_not.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright (c) Marshall Clow 2011-2012.
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. */
  6. /// \file find_if_not.hpp
  7. /// \brief Find the first element in a sequence that does not satisfy a predicate.
  8. /// \author Marshall Clow
  9. #ifndef BOOST_ALGORITHM_FIND_IF_NOT_HPP
  10. #define BOOST_ALGORITHM_FIND_IF_NOT_HPP
  11. #include <boost/range/begin.hpp>
  12. #include <boost/range/end.hpp>
  13. namespace boost { namespace algorithm {
  14. /// \fn find_if_not(InputIterator first, InputIterator last, Predicate p)
  15. /// \brief Finds the first element in the sequence that does not satisfy the predicate.
  16. /// \return The iterator pointing to the desired element.
  17. ///
  18. /// \param first The start of the input sequence
  19. /// \param last One past the end of the input sequence
  20. /// \param p A predicate for testing the elements of the range
  21. /// \note This function is part of the C++2011 standard library.
  22. template<typename InputIterator, typename Predicate>
  23. BOOST_CXX14_CONSTEXPR InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p )
  24. {
  25. for ( ; first != last; ++first )
  26. if ( !p(*first))
  27. break;
  28. return first;
  29. }
  30. /// \fn find_if_not ( const Range &r, Predicate p )
  31. /// \brief Finds the first element in the sequence that does not satisfy the predicate.
  32. /// \return The iterator pointing to the desired element.
  33. ///
  34. /// \param r The input range
  35. /// \param p A predicate for testing the elements of the range
  36. ///
  37. template<typename Range, typename Predicate>
  38. BOOST_CXX14_CONSTEXPR typename boost::range_iterator<const Range>::type find_if_not ( const Range &r, Predicate p )
  39. {
  40. return boost::algorithm::find_if_not (boost::begin (r), boost::end(r), p);
  41. }
  42. }}
  43. #endif // BOOST_ALGORITHM_FIND_IF_NOT_HPP