@@ -18,6 +18,7 @@ namespace rusty_iterators::interface
1818using concepts::AllFunctor;
1919using concepts::AnyFunctor;
2020using concepts::Comparable;
21+ using concepts::EqFunctor;
2122using concepts::FilterFunctor;
2223using concepts::FoldFunctor;
2324using concepts::ForEachFunctor;
@@ -76,6 +77,13 @@ class IterInterface
7677 template <class Second >
7778 [[nodiscard]] auto chain (Second&& it) -> Chain<T, Derived, Second>;
7879
80+ template <class Other >
81+ [[nodiscard]] auto eq (Other&& it) -> bool;
82+
83+ template <class Other , class Functor >
84+ requires EqFunctor<T, Functor>
85+ [[nodiscard]] auto eqBy (Other&& it, Functor&& f) -> bool;
86+
7987 template <class Functor >
8088 requires FilterFunctor<T, Functor>
8189 [[nodiscard]] auto filter (Functor&& f) -> Filter<T, Functor, Derived>;
@@ -244,6 +252,22 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::chain(Second&& it)
244252 return Chain<T, Derived, Second>{std::forward<Derived>(self ()), std::forward<Second>(it)};
245253}
246254
255+ template <class T , class Derived >
256+ template <class Other >
257+ auto rusty_iterators::interface::IterInterface<T, Derived>::eq(Other&& it) -> bool
258+ {
259+ return self ().eqBy (std::forward<Other>(it),
260+ [](auto x) { return std::get<0 >(x) == std::get<1 >(x); });
261+ }
262+
263+ template <class T , class Derived >
264+ template <class Other , class Functor >
265+ requires rusty_iterators::concepts::EqFunctor<T, Functor>
266+ auto rusty_iterators::interface::IterInterface<T, Derived>::eqBy(Other&& it, Functor&& f) -> bool
267+ {
268+ return self ().zip (std::forward<Other>(it)).all (std::forward<Functor>(f));
269+ }
270+
247271template <class T , class Derived >
248272template <class Functor >
249273 requires rusty_iterators::iterator::FilterFunctor<T, Functor>
@@ -312,15 +336,15 @@ template <class R>
312336 requires rusty_iterators::concepts::Comparable<R>
313337auto rusty_iterators::interface::IterInterface<T, Derived>::max() -> std::optional<R>
314338{
315- return reduce ([](auto x, auto y) { return std::max (x, y); });
339+ return self (). reduce ([](auto x, auto y) { return std::max (x, y); });
316340}
317341
318342template <class T , class Derived >
319343template <class R >
320344 requires rusty_iterators::concepts::Comparable<R>
321345auto rusty_iterators::interface::IterInterface<T, Derived>::min() -> std::optional<R>
322346{
323- return reduce ([](auto x, auto y) { return std::min (x, y); });
347+ return self (). reduce ([](auto x, auto y) { return std::min (x, y); });
324348}
325349
326350template <class T , class Derived >
@@ -333,7 +357,7 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::movingWindow(size_t
333357template <class T , class Derived >
334358auto rusty_iterators::interface::IterInterface<T, Derived>::nth(size_t element) -> std::optional<T>
335359{
336- return advanceBy (element).next ();
360+ return self (). advanceBy (element).next ();
337361}
338362
339363template <class T , class Derived >
@@ -379,7 +403,7 @@ template <class R>
379403 requires rusty_iterators::concepts::Summable<R>
380404auto rusty_iterators::interface::IterInterface<T, Derived>::sum() -> R
381405{
382- return fold (R{}, [](auto acc, auto x) { return acc + x; });
406+ return self (). fold (R{}, [](auto acc, auto x) { return acc + x; });
383407}
384408
385409template <class T , class Derived >
0 commit comments