Support Class Library
A set of tools providing classes and utility
forEach.h
Go to the documentation of this file.
1 #pragma once
4 #include <functional>
5 #include <scl/stream/Stream.h>
7 
8 namespace scl{
9  namespace stream{
10  namespace terminators{
11  namespace details{
16  template <class T>
18  public:
25 
30  using consumer_type = std::function<void(const value_type&)>;
31 
38  }
39 
40  void process(){
41  while(this->hasNext()){
42  auto v = this->next();
43  if(v.isValid())
44  v.value().ifSome(consumer);
45  }
46  /*for(auto payload : *this) {
47  if(payload.isValid())
48  payload.value().doIfPresent(consumer);
49  }*/
50  };
51 
52  protected:
58  };
59 
60 
65  template <class T>
72 
78  };
79  }
80 
89  template <
90  class F,
91  class Fn = decltype(META::as_fn(std::declval<F>())),
92  class T = META::remove_cv_ref_t<META::arg_t<Fn, 0>>
93  >
95  return {callback};
96  }
97 
104  template <class T>
106  return {cb};
107  }
108 
115  template <class T>
116  void operator|(const Stream<T>& lhs, const details::for_each_toolbox<T>& rhs){
117  auto terminator = details::ForEachTerminator<T>{lhs.it(), rhs.callback};
118  terminator.process();
119  }
120  }
121  }
122 }
BaseStreamIterator< T > parent_iterator_type
Type alias for the "parent" iterator.
typename payload_type::value_type value_type
Type alias for the data type manipulated.
void process()
Process the return value.
Definition: forEach.h:40
Global namespace of the SCL.
Definition: alias.hpp:3
void operator|(const Stream< T > &lhs, const details::for_each_toolbox< T > &rhs)
Pipe operator overload for forEach terminators.
Definition: forEach.h:116
it_t it() const
Get a reference to the underlying iterator.
Definition: Stream.h:48
typename iterator_type::parent_type parent_type
Definition: forEach.h:24
std_fn_type< R(*)(Args...)> as_fn(R(*f)(Args...))
Definition: fn_introspect.h:89
typename OpStreamIterator< T >::parent_type parent_type
details::for_each_toolbox< T > forEach_(typename details::for_each_toolbox< T >::callback_t cb)
Invoke a function on each element of a stream by providing the type arguments.
Definition: forEach.h:105
std::function< void(const value_type &)> consumer_type
The type of functions to call on each element.
Definition: forEach.h:30
typename iterator_type::result_type result_type
Definition: forEach.h:22
details::for_each_toolbox< T > forEach(F callback)
Invoke a function on each element of a stream.
Definition: forEach.h:94
typename ForEachTerminator< T >::consumer_type callback_t
The function type of a callback.
Definition: forEach.h:71
typename iterator_type::payload_type payload_type
Type alias for the payload used.
consumer_type consumer
the function to call on each element
Definition: forEach.h:57
A class for iterators used in end operations.
typename iterator_type::parent_iterator_type parent_iterator_type
Definition: forEach.h:23
ForEachTerminator(parent_type p, consumer_type c)
Construct a terminator from its parent and a consumer.
Definition: forEach.h:37
A class representing a stream iterator&#39;s payload.
Definition: payload.h:16
Class representing a stream of data.
Definition: Stream.h:15
void result_type
Type alias for the computed result.