is_sorted.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright Bryce Lelbach 2010
  2. // Copyright Neil Groves 2009. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED
  11. #define BOOST_RANGE_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED
  12. #include <boost/concept_check.hpp>
  13. #include <boost/range/begin.hpp>
  14. #include <boost/range/end.hpp>
  15. #include <boost/range/concepts.hpp>
  16. #include <boost/range/value_type.hpp>
  17. #include <boost/detail/is_sorted.hpp>
  18. #include <algorithm>
  19. namespace boost
  20. {
  21. namespace range
  22. {
  23. /// \brief template function is_sorted
  24. ///
  25. /// range-based version of the is_sorted std algorithm
  26. ///
  27. /// \pre SinglePassRange is a model of the SinglePassRangeConcept
  28. template<class SinglePassRange>
  29. inline bool is_sorted(const SinglePassRange& rng)
  30. {
  31. BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>));
  32. BOOST_RANGE_CONCEPT_ASSERT((LessThanComparableConcept<BOOST_DEDUCED_TYPENAME
  33. range_value<const SinglePassRange>::type>));
  34. return ::boost::detail::is_sorted(boost::begin(rng), boost::end(rng));
  35. }
  36. /// \overload
  37. template<class SinglePassRange, class BinaryPredicate>
  38. inline bool is_sorted(const SinglePassRange& rng, BinaryPredicate pred)
  39. {
  40. BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>));
  41. BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept<BinaryPredicate,
  42. BOOST_DEDUCED_TYPENAME range_value<const SinglePassRange>::type,
  43. BOOST_DEDUCED_TYPENAME range_value<const SinglePassRange>::type>));
  44. return ::boost::detail::is_sorted(boost::begin(rng), boost::end(rng), pred);
  45. }
  46. } // namespace range
  47. using range::is_sorted;
  48. } // namespace boost
  49. #endif // include guard