source.hpp 1.2 KB

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