find_if_not.hpp 1.9 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/config.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. namespace boost { namespace algorithm {
  15. /// \fn find_if_not(InputIterator first, InputIterator last, Predicate p)
  16. /// \brief Finds the first element in the sequence that does not satisfy the predicate.
  17. /// \return The iterator pointing to the desired element.
  18. ///
  19. /// \param first The start of the input sequence
  20. /// \param last One past the end of the input sequence
  21. /// \param p A predicate for testing the elements of the range
  22. /// \note This function is part of the C++2011 standard library.
  23. template<typename InputIterator, typename Predicate>
  24. BOOST_CXX14_CONSTEXPR InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p )
  25. {
  26. for ( ; first != last; ++first )
  27. if ( !p(*first))
  28. break;
  29. return first;
  30. }
  31. /// \fn find_if_not ( const Range &r, Predicate p )
  32. /// \brief Finds the first element in the sequence that does not satisfy the predicate.
  33. /// \return The iterator pointing to the desired element.
  34. ///
  35. /// \param r The input range
  36. /// \param p A predicate for testing the elements of the range
  37. ///
  38. template<typename Range, typename Predicate>
  39. BOOST_CXX14_CONSTEXPR typename boost::range_iterator<const Range>::type find_if_not ( const Range &r, Predicate p )
  40. {
  41. return boost::algorithm::find_if_not (boost::begin (r), boost::end(r), p);
  42. }
  43. }}
  44. #endif // BOOST_ALGORITHM_FIND_IF_NOT_HPP