| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // equal.h
- // stream
- //
- // Created by Sam Jaffe on 4/2/23.
- //
- #pragma once
- #include <stream/forward.h>
- #include <stream/detail/invoke.h>
- #include <stream/detail/traits.h>
- #include <stream/detail/macro.h>
- namespace stream::range {
- template <typename It1, typename S1, typename It2, typename S2,
- typename Cmp = std::equal_to<>, typename Proj1 = detail::identity,
- typename Proj2 = detail::identity,
- REQUIRES((detail::is_comparable_v<It1, S1> &&
- detail::is_comparable_v<It2, S2>))>
- bool equal(It1 it1, S1 end1, It2 it2, S2 end2, Cmp cmp = {}, Proj1 proj1 = {},
- Proj2 proj2 = {}) {
- if constexpr (detail::is_sized_sentinel_v<It1, S1> &&
- detail::is_sized_sentinel_v<It2, S2>) {
- if ((end1 - it1) != (end2 - it2)) { return false; }
- }
- for (; it1 != end1 && it2 != end2; ++it1, ++it2) {
- if (!detail::invoke(cmp, *it1, *it2, proj1, proj2)) { return false; }
- }
- return (it1 == end1) && (it2 == end2);
- }
- template <typename R1, typename R2, typename Cmp = std::equal_to<>,
- typename Proj1 = detail::identity, typename Proj2 = detail::identity>
- bool equal(R1 const r1, R2 const & r2, Cmp cmp = {}, Proj1 proj1 = {},
- Proj2 proj2 = {}) {
- return equal(r1.begin(), r1.end(), r2.begin(), r2.end(), std::ref(cmp),
- std::ref(proj1), std::ref(proj2));
- }
- }
- #include <stream/detail/undef.h>
|