Support Class Library
A set of tools providing classes and utility
array.h
Go to the documentation of this file.
1 #pragma once
3 #include <array>
7 
8 namespace scl{
9  namespace stream{
10  namespace creators{
11  namespace details{
17  template <class T, size_t N>
19  public:
23 
24  protected:
29  std::array<T, N> arr;
30 
35  size_t index = 0;
36 
37  public:
42  explicit constexpr FromArrayIterator(std::array<T, N> arr) : arr{std::move(arr)}{
43  }
44 
45  constexpr bool hasNext() const override{ return this->index < N; }
46 
47  payload_type next() override{
48  if(!this->hasNext())
49  return payload_type::withoutValue();
50 
51  const auto& value = this->arr[this->index];
52  this->index += 1;
53 
54  return payload_type::withValue(value);
55  }
56 
57  /*FromArrayIterator<T, N> clone() const override{
58  return FromArrayIterator{this->arr};
59  }*/
60  };
61  }
62 
70  template <class T, size_t N>
71  Stream<T> streamFrom(std::array<T, N> a){
72  using namespace scl::tools;
73  return Stream<T>{
74  make::ptr<details::FromArrayIterator<T, N>>(std::move(a))
75  };
76  }
77  }
78  }
79 }
constexpr FromArrayIterator(std::array< T, N > arr)
Construct from a std::array.
Definition: array.h:42
constexpr bool hasNext() const override
Determines whether or not this iterator can produce another value payload.
Definition: array.h:45
StreamIteratorPayload< T > payload_type
Type alias for the payload used.
typename payload_type::value_type value_type
Type alias for the data type manipulated.
Global namespace of the SCL.
Definition: alias.hpp:3
size_t index
The next index to get data from.
Definition: array.h:35
std::array< T, N > arr
The underlying array.
Definition: array.h:29
typename iterator_type::value_type value_type
Definition: array.h:21
General purpose tooling.
Definition: iostream.hpp:4
A class for iterators that start a stream chain.
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: array.h:22
Class representing a stream of data.
Definition: Stream.h:15
payload_type next() override
Retrieve the next iterator payload.
Definition: array.h:47