| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #pragma once
- #include <functional>
- #include <stream/forward.h>
- #include <stream/detail/traits.h>
- #include <stream/iterator/sentinel.h>
- #include <stream/iterator/transform_iterator.h>
- #include <stream/view/interface.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename S, typename Proj>
- class transform_view : public proxy_view_interface<transform_view<S, Proj>, S,
- transform_iterator, Proj> {
- public:
- using iterator = transform_iterator<detail::begin_t<S>, Proj>;
- private:
- S stream_;
- Proj projection_;
- public:
- transform_view(S && stream, Proj projection)
- : stream_(FWD(stream)), projection_(projection) {}
- auto begin() const { return iterator(stream_.begin(), projection_); }
- auto end() const { return sentinel_end(this, stream_, projection_); }
- };
- template <typename S, typename Proj>
- transform_view(S &&, Proj) -> transform_view<S, Proj>;
- }
- namespace stream::ranges::views {
- template <typename Proj> class transform {
- public:
- transform(Proj const & projection) : projection_(projection) {}
- template <typename Stream>
- friend auto operator|(Stream && stream, transform map) {
- // TODO: if constexpr transform_view
- return transform_view(FWD(stream), std::move(map.projection_));
- }
- private:
- Proj projection_;
- };
- }
- #include <stream/detail/undef.h>
|