Support Class Library
A set of tools providing classes and utility
stl_iterators.h
Go to the documentation of this file.
1 #pragma once
4 #include <scl/macros.h>
5 #include <iterator>
7 
8 namespace scl{
9  namespace stream{
10  namespace creators{
11  namespace details{
16  template <class It>
17  using iterator_value_type = typename std::iterator_traits<It>::value_type;
18 
23  template <class It>
25  public:
29 
30  protected:
38  It begin, end;
39 
40  public:
46  FromStlIterator(It begin, It end) : begin{begin}, end{end} {
47  }
48 
49  bool hasNext() const override{ return begin != end; }
50 
51  payload_type next() override{
52  if(!this->hasNext())
53  return payload_type::withoutValue();
54 
55  const value_type& value = *(begin++);
56  return payload_type::withValue(value);
57  }
58 
59  /*FromStlIterator<It> clone() override{}*/
60  };
61  }
62 
70  template <class It>
72  using namespace scl::tools;
74  make::ptr<details::FromStlIterator<It>>(begin, end)
75  };
76  }
77  }
78  }
79 }
Creator for an iterator-based range.
Definition: stl_iterators.h:24
StreamIteratorPayload< T > payload_type
Type alias for the payload used.
Global namespace of the SCL.
Definition: alias.hpp:3
typename std::iterator_traits< It >::value_type iterator_value_type
A type alias for the value type from the iterator traits.
Definition: stl_iterators.h:17
payload_type next() override
Retrieve the next iterator payload.
Definition: stl_iterators.h:51
bool hasNext() const override
Determines whether or not this iterator can produce another value payload.
Definition: stl_iterators.h:49
virtual StlAdapter< iterator_value_type< It > > end()
Retrieve a stl-like iterator for the end of this stream iterator.
virtual StlAdapter< iterator_value_type< It > > begin()
Retrieve a stl-like iterator for this stream iterator.
General purpose tooling.
Definition: iostream.hpp:4
A class for iterators that start a stream chain.
It end
the iterator to the point after the last element
Definition: stl_iterators.h:38
Stream< T > streamFrom(std::array< T, N > a)
Create an scl::stream::Stream from a std::array.
Definition: array.h:71
typename iterator_type::payload_type payload_type
Definition: stl_iterators.h:28
FromStlIterator(It begin, It end)
Construct the iterator from STL-like iterators.
Definition: stl_iterators.h:46
Class representing a stream of data.
Definition: Stream.h:15