You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.5KB

  1. // Range v3 library
  2. //
  3. // Copyright 2019 Christopher Di Bella
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #ifndef RANGES_V3_ALGORITHM_STARTS_WITH_HPP
  12. #define RANGES_V3_ALGORITHM_STARTS_WITH_HPP
  13. #include <utility>
  14. #include <range/v3/range_fwd.hpp>
  15. #include <range/v3/algorithm/equal.hpp>
  16. #include <range/v3/algorithm/mismatch.hpp>
  17. #include <range/v3/functional/comparisons.hpp>
  18. #include <range/v3/functional/identity.hpp>
  19. #include <range/v3/iterator/concepts.hpp>
  20. #include <range/v3/iterator/operations.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. // template<typename I1, typename I2>
  30. // struct starts_with_result : detail::in1_in2_result<I1, I2>
  31. // {
  32. // bool result;
  33. // };
  34. RANGES_BEGIN_NIEBLOID(starts_with)
  35. /// \brief function template \c starts_with
  36. template<typename I1,
  37. typename S1,
  38. typename I2,
  39. typename S2,
  40. typename Comp = equal_to,
  41. typename Proj1 = identity,
  42. typename Proj2 = identity>
  43. constexpr auto RANGES_FUN_NIEBLOID(starts_with)(I1 first1,
  44. S1 last1,
  45. I2 first2,
  46. S2 last2,
  47. Comp comp = {},
  48. Proj1 proj1 = {},
  49. Proj2 proj2 = {}) //
  50. ->CPP_ret(bool)( //
  51. requires input_iterator<I1> && sentinel_for<S1, I1> &&
  52. input_iterator<I2> && sentinel_for<S2, I2> &&
  53. indirectly_comparable<I1, I2, Comp, Proj1, Proj2>)
  54. {
  55. return mismatch(std::move(first1),
  56. std::move(last1),
  57. std::move(first2),
  58. last2,
  59. std::move(comp),
  60. std::move(proj1),
  61. std::move(proj2))
  62. .in2 == last2;
  63. }
  64. /// \overload
  65. template<typename R1,
  66. typename R2,
  67. typename Comp = equal_to,
  68. typename Proj1 = identity,
  69. typename Proj2 = identity>
  70. constexpr auto RANGES_FUN_NIEBLOID(starts_with)(
  71. R1 && r1, R2 && r2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) //
  72. ->CPP_ret(bool)( //
  73. requires input_range<R1> && input_range<R2> &&
  74. indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Comp, Proj1, Proj2>)
  75. {
  76. return (*this)( //
  77. begin(r1),
  78. end(r1),
  79. begin(r2),
  80. end(r2),
  81. std::move(comp),
  82. std::move(proj1),
  83. std::move(proj2));
  84. }
  85. RANGES_END_NIEBLOID(starts_with)
  86. /// @}
  87. } // namespace ranges
  88. #endif // RANGES_V3_ALGORITHM_STARTS_WITH_HPP