#pragma once namespace stream { template struct map_t { template explicit map_t(F&& f) : func(f) {} std::function func; }; } template stream::detail::stream_base operator|(stream::detail::stream_base const&s, stream::map_t&& f) { return s.map(f.func); } template stream::detail::stream_base operator|(stream::detail::stream_base &&s, stream::map_t&& f) { return std::move(s).map(f.func); } namespace stream { namespace detail { template class map_stream : public stream_impl { public: class iterator : public iterator_impl { public: typedef iterator_impl super; iterator(std::function f, ::stream::iterator&& impl) : fun_(f), impl_(std::forward<::stream::iterator>(impl)) {} ~iterator() {} R operator*() override { return fun_(*impl_); } DELEGATE_ITERATOR_IMPL(impl_) private: std::function fun_; ::stream::iterator impl_; }; template map_stream(F&& func, stream_base const& sb) : fun_(func), source_(sb) {} template map_stream(F&& func, stream_base && sb) : fun_(func), source_(std::forward>(sb)) { } ~map_stream() override {} ::stream::iterator begin() override { return new iterator{fun_, source_.begin()};} ::stream::iterator end() override { return new iterator{fun_, source_.end()}; } private: std::function fun_; stream_base source_; }; template template auto stream_base::map(F&& func) const& -> stream_base, true> { using impl_t = map_stream, false>; return stream_base, true>{new impl_t(func, falsify(*this))}; } template template auto stream_base::map(F&& func) && -> stream_base, true> { using impl_t = map_stream, Own>; return stream_base, true>{new impl_t(func, std::forward(*this))}; } } }