lexicographical_compare.hpp 2.1 KB

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