|
|
@@ -1,23 +1,23 @@
|
|
|
#pragma once
|
|
|
|
|
|
-namespace stream { namespace detail {
|
|
|
- template <typename T, typename R> class map_iterator {
|
|
|
+#include <iterator/proxy.h>
|
|
|
+
|
|
|
+namespace stream::detail {
|
|
|
+ template <typename T, typename R>
|
|
|
+ class map_iterator
|
|
|
+ : public ::iterator::proxy<iterator<T>, map_iterator<T, R>> {
|
|
|
+ public:
|
|
|
+ using projection_t = std::function<R(T const &)>;
|
|
|
+ using super_t = ::iterator::proxy<iterator<T>, map_iterator<T, R>>;
|
|
|
+
|
|
|
public:
|
|
|
- map_iterator(std::function<R(T const &)> f, iterator<T> && impl)
|
|
|
- : fun_(f), impl_(std::forward<iterator<T>>(impl)) {}
|
|
|
-
|
|
|
- R operator*() { return fun_(*impl_); }
|
|
|
- map_iterator & operator++() {
|
|
|
- ++impl_;
|
|
|
- return *this;
|
|
|
- }
|
|
|
- bool operator==(map_iterator const & rhs) const {
|
|
|
- return impl_ == rhs.impl_;
|
|
|
- }
|
|
|
+ map_iterator(projection_t proj, iterator<T> && impl)
|
|
|
+ : proj_(std::move(proj)), super_t(std::move(impl)) {}
|
|
|
+
|
|
|
+ R dereference() const { return proj_(super_t::dereference()); }
|
|
|
|
|
|
private:
|
|
|
- std::function<R(T const &)> fun_;
|
|
|
- iterator<T> impl_;
|
|
|
+ std::function<R(T const &)> proj_;
|
|
|
};
|
|
|
|
|
|
template <typename T, typename R> class map_stream {
|
|
|
@@ -47,4 +47,4 @@ namespace stream { namespace detail {
|
|
|
stream_base<traits::mapped_t<T, F>> stream_base<T>::map(F && func) const & {
|
|
|
return std::make_shared<map_stream<T, traits::mapped_t<T, F>>>(func, *this);
|
|
|
}
|
|
|
-}}
|
|
|
+}
|