source.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. namespace stream {
  3. namespace detail {
  4. namespace source {
  5. template <typename C>
  6. class iterator : public iterator_impl<typename C::value_type> {
  7. public:
  8. typedef iterator_impl<typename C::value_type> super;
  9. explicit iterator(typename C::iterator it) : impl_(it) {}
  10. ~iterator() {}
  11. typename C::value_type operator*() override { return *impl_; }
  12. DELEGATE_ITERATOR_IMPL(impl_)
  13. private:
  14. typename C::const_iterator impl_;
  15. };
  16. }
  17. template <typename C>
  18. class source_stream : public stream_impl<typename C::value_type> {
  19. public:
  20. typedef typename C::value_type value_type;
  21. explicit source_stream(C const& cont) : source_(cont) {}
  22. explicit source_stream(C && cont) : source_(std::forward(cont)) {}
  23. ~source_stream() override {}
  24. iterator<value_type> begin() override { return {new source::iterator<C>{source_.begin()}}; }
  25. iterator<value_type> end() override { return {new source::iterator<C>{source_.end()}}; }
  26. private:
  27. C source_;
  28. };
  29. }
  30. template <typename C>
  31. detail::stream_base<typename C::value_type> make_stream(C const& cont) {
  32. return {std::make_shared<detail::source_stream<C>>(cont)};
  33. }
  34. }