equal.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // equal.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 4/2/23.
  6. //
  7. #pragma once
  8. #include <stream/forward.h>
  9. #include <stream/detail/invoke.h>
  10. #include <stream/detail/traits.h>
  11. #include <stream/detail/macro.h>
  12. namespace stream::range {
  13. template <typename It1, typename S1, typename It2, typename S2,
  14. typename Cmp = std::equal_to<>, typename Proj1 = detail::identity,
  15. typename Proj2 = detail::identity,
  16. REQUIRES((detail::is_comparable_v<It1, S1> &&
  17. detail::is_comparable_v<It2, S2>))>
  18. bool equal(It1 it1, S1 end1, It2 it2, S2 end2, Cmp cmp = {}, Proj1 proj1 = {},
  19. Proj2 proj2 = {}) {
  20. for (; it1 != end1 && it2 != end2; ++it1, ++it2) {
  21. if (!detail::invoke(cmp, *it1, *it2, proj1, proj2)) { return false; }
  22. }
  23. return (it1 == end1) && (it2 == end2);
  24. }
  25. template <typename R1, typename R2, typename Cmp = std::equal_to<>,
  26. typename Proj1 = detail::identity, typename Proj2 = detail::identity>
  27. bool equal(R1 const r1, R2 const & r2, Cmp cmp = {}, Proj1 proj1 = {},
  28. Proj2 proj2 = {}) {
  29. return equal(r1.begin(), r1.end(), r2.begin(), r2.end(), cmp, proj1, proj2);
  30. }
  31. }
  32. #include <stream/detail/undef.h>