Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

lexicographical_compare.hpp 3.5KB

vor 5 Jahren
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #ifndef RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
  14. #define RANGES_V3_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/functional/comparisons.hpp>
  17. #include <range/v3/functional/identity.hpp>
  18. #include <range/v3/functional/invoke.hpp>
  19. #include <range/v3/iterator/concepts.hpp>
  20. #include <range/v3/iterator/traits.hpp>
  21. #include <range/v3/range/access.hpp>
  22. #include <range/v3/range/concepts.hpp>
  23. #include <range/v3/range/traits.hpp>
  24. #include <range/v3/utility/static_const.hpp>
  25. namespace ranges
  26. {
  27. /// \addtogroup group-algorithms
  28. /// @{
  29. RANGES_BEGIN_NIEBLOID(lexicographical_compare)
  30. /// \brief function template \c lexicographical_compare
  31. template<typename I0,
  32. typename S0,
  33. typename I1,
  34. typename S1,
  35. typename C = less,
  36. typename P0 = identity,
  37. typename P1 = identity>
  38. auto RANGES_FUN_NIEBLOID(lexicographical_compare)(I0 begin0,
  39. S0 end0,
  40. I1 begin1,
  41. S1 end1,
  42. C pred = C{},
  43. P0 proj0 = P0{},
  44. P1 proj1 = P1{})
  45. ->CPP_ret(bool)( //
  46. requires input_iterator<I0> && sentinel_for<S0, I0> &&
  47. input_iterator<I1> && sentinel_for<S1, I1> &&
  48. indirect_strict_weak_order<C, projected<I0, P0>, projected<I1, P1>>)
  49. {
  50. for(; begin1 != end1; ++begin0, ++begin1)
  51. {
  52. if(begin0 == end0 ||
  53. invoke(pred, invoke(proj0, *begin0), invoke(proj1, *begin1)))
  54. return true;
  55. if(invoke(pred, invoke(proj1, *begin1), invoke(proj0, *begin0)))
  56. return false;
  57. }
  58. return false;
  59. }
  60. /// \overload
  61. template<typename Rng0,
  62. typename Rng1,
  63. typename C = less,
  64. typename P0 = identity,
  65. typename P1 = identity>
  66. auto RANGES_FUN_NIEBLOID(lexicographical_compare)(
  67. Rng0 && rng0, Rng1 && rng1, C pred = C{}, P0 proj0 = P0{}, P1 proj1 = P1{}) //
  68. ->CPP_ret(bool)( //
  69. requires input_range<Rng0> && input_range<Rng1> &&
  70. indirect_strict_weak_order<C,
  71. projected<iterator_t<Rng0>, P0>,
  72. projected<iterator_t<Rng1>, P1>>)
  73. {
  74. return (*this)(begin(rng0),
  75. end(rng0),
  76. begin(rng1),
  77. end(rng1),
  78. std::move(pred),
  79. std::move(proj0),
  80. std::move(proj1));
  81. }
  82. RANGES_END_NIEBLOID(lexicographical_compare)
  83. namespace cpp20
  84. {
  85. using ranges::lexicographical_compare;
  86. }
  87. /// @}
  88. } // namespace ranges
  89. #endif // include guard