| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #pragma once
- #include <iterator>
- #include <iterator/detail/facade_traits.h>
- #include <stream/forward.h>
- #include <iterator/detail/macro.h>
- namespace stream::ranges {
- template <typename It, typename S = It> class subrange {
- private:
- It begin_;
- S end_;
- public:
- subrange(It begin, S end) : begin_(begin), end_(end) {}
- template <typename C, REQUIRES(detail::is_container_v<C>)>
- subrange(C && container)
- : subrange(std::begin(container), std::end(container)) {
- // TODO: permissible dangling
- static_assert(std::is_reference_v<C>,
- "Cannot access iterator of a temporary");
- }
- auto begin() const { return begin_; }
- auto end() const { return end_; }
- bool empty() const { return begin_ == end_; }
- SFINAE(detail::has_distance_to_v<It>, size_t) size() const {
- return end_ - begin_;
- }
- };
- template <typename It, typename S> subrange(It, S) -> subrange<It, S>;
- template <typename C>
- subrange(C &&) -> subrange<detail::begin_t<C>, detail::end_t<C>>;
- }
- #include <iterator/detail/undef.h>
|