Support Class Library
A set of tools providing classes and utility
toVector.h
Go to the documentation of this file.
1 #pragma once
3 #include <vector>
4 #include <scl/stream/Stream.h>
6 
7 namespace scl{
8  namespace stream{
9  namespace terminators {
10  namespace pack {
11  namespace details {
17  template<class T, class Allocator = std::allocator<T>>
18  class VectorPacker : public stream::details::iterator::EndStreamIterator<std::vector<T, Allocator>, T> {
19  public:
26 
31  using allocator_type = Allocator;
32 
33  explicit VectorPacker(parent_type p) : iterator_type{std::move(p)} {
34  }
35 
37  result_type ret = {};
38 
39  /*while (this->hasNext()) {
40  const auto& alt = this->next().value();
41  if (alt.hasValue())
42  ret.push_back(*alt);
43  }*/
44 
45  for(auto&& payload : *this){
46  if(payload.isValid())
47  ret.push_back(*payload.value());
48  }
49 
50  return ret;
51  }
52  };
53 
58 
63  template <class Allocator>
65  }
66 
72 
77  template <class Allocator>
79  }
80 
88  template<class T>
90  auto packer = pack::details::VectorPacker<T>{lhs.it()};
91  return packer.process();
92  }
93 
102  template<class T, class Allocator>
104  auto packer = pack::details::VectorPacker<T, Allocator>{lhs.it()};
105  return packer.process();
106  }
107  }
108  }
109 }
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.
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::result_type result_type
Definition: toVector.h:23
Tag type to pack into a vector w/ control over the allocator.
Definition: toVector.h:64
typename iterator_type::parent_type parent_type
Definition: toVector.h:25
Allocator allocator_type
The type of allocator used w/ std::vector.
Definition: toVector.h:31
constexpr scl::utils::Placeholder _
Definition: Placeholder.h:39
typename iterator_type::parent_iterator_type parent_iterator_type
Definition: toVector.h:24
details::to_vector_toolbox toVector()
Terminator that packs into a vector.
Definition: toVector.h:71
Tag type to pack into a vector w/ default template parameters.
Definition: toVector.h:57
typename iterator_type::payload_type payload_type
Type alias for the payload used.
A class for iterators used in end operations.
Class that allows packing to a std::vector.
Definition: toVector.h:18
result_type process()
Process the return value.
Definition: toVector.h:36
A class representing a stream iterator&#39;s payload.
Definition: payload.h:16
Class representing a stream of data.
Definition: Stream.h:15
std::vector< T, Allocator > result_type
Type alias for the computed result.