18 template<
typename TContainer>
19 requires concepts::SourceContainer<std::remove_cvref_t<TContainer>>
27 std::unique_ptr<TContainer> container;
30 SrcMov(TContainer&& container) : container(std::make_unique<TContainer>(std::move(container))), iter(
Src::initIterator(*this->container)) {}
34 template<
typename TContainer>
39 using Item =
typename Src::Item;
42 if(!Src::hasNext(*self.container, self.iter)) [[unlikely]] {
return {}; }
43 return std::move(Src::next(*self.container, self.iter));
45 static constexpr inline SizeHint
sizeHint(
const Self& self) {
return Src::sizeHint(*self.container); }
46 static constexpr inline size_t advanceBy(
Self& self,
size_t n) {
47 return Src::skipN(*self.container, self.iter, n);
51 template<
typename TContainer>
52 requires concepts::DoubleEndedSourceContainer<std::remove_cvref_t<TContainer>>
53 struct trait::DoubleEndedIterator<SrcMov<TContainer>> {
54 using Src = trait::Source<TContainer>;
55 using Item =
typename Src::Item;
58 static constexpr inline IterValue<Item>
nextBack(SrcMov<TContainer>& self) {
59 if(!Src::hasNext(*self.container, self.iter)) [[unlikely]] {
return {}; }
60 return std::move(Src::nextBack(*self.container, self.iter));
64 template<
typename TContainer>
65 struct trait::ExactSizeIterator<SrcMov<TContainer>> {
66 static constexpr inline size_t size(
const SrcMov<TContainer>& self) {
return self.container->size(); }
69 template<
typename TContainer>
70 requires util::ContiguousMemoryContainer<TContainer>
71 struct trait::ContiguousMemoryIterator<SrcMov<TContainer>> {
72 using ItemPtr = std::add_pointer_t<std::remove_reference_t<typename SrcMov<TContainer>::Item>>;
90 template<
typename TContainer>
91 requires concepts::SourceContainer<std::remove_cvref_t<TContainer>>
99 TContainer& container;
106 template<
typename TContainer>
111 using Item =
typename Src::ItemRef;
114 if(!Src::hasNext(self.container, self.iter)) [[unlikely]] {
return {}; }
115 return Src::next(self.container, self.iter);
117 static constexpr inline SizeHint
sizeHint(
const Self& self) {
return Src::sizeHint(self.container); }
118 static constexpr inline size_t advanceBy(
Self& self,
size_t n) {
119 return Src::skipN(self.container, self.iter, n);
123 template<
typename TContainer>
124 requires concepts::DoubleEndedSourceContainer<std::remove_cvref_t<TContainer>>
125 struct trait::DoubleEndedIterator<SrcRef<TContainer>> {
126 using Src = trait::Source<TContainer>;
127 using Item =
typename Src::ItemRef;
130 static constexpr inline IterValue<Item>
nextBack(SrcRef<TContainer>& self) {
131 if(!Src::hasNext(self.container, self.iter)) [[unlikely]] {
return {}; }
132 return Src::nextBack(self.container, self.iter);
136 template<
typename TContainer>
137 struct trait::ExactSizeIterator<SrcRef<TContainer>> {
138 static constexpr inline size_t size(
const SrcRef<TContainer>& self) {
return self.container.size(); }
141 template<
typename TContainer>
142 requires util::ContiguousMemoryContainer<TContainer>
143 struct trait::ContiguousMemoryIterator<SrcRef<TContainer>> {
144 using ItemPtr = std::add_pointer_t<std::remove_reference_t<typename SrcRef<TContainer>::Item>>;
161 template<
typename TContainer>
162 requires concepts::SourceContainer<std::remove_cvref_t<TContainer>>
170 const TContainer& container;
177 template<
typename TContainer>
182 using Item =
typename Src::ItemConstRef;
185 if(!Src::hasNext(self.container, self.iter)) [[unlikely]] {
return {}; }
186 return Src::next(self.container, self.iter);
188 static constexpr inline SizeHint
sizeHint(
const Self& self) {
return Src::sizeHint(self.container); }
189 static constexpr inline size_t advanceBy(
Self& self,
size_t n) {
190 return Src::skipN(self.container, self.iter, n);
194 template<
typename TContainer>
195 requires concepts::DoubleEndedSourceContainer<std::remove_cvref_t<TContainer>>
196 struct trait::DoubleEndedIterator<SrcCRef<TContainer>> {
197 using Src = trait::Source<TContainer>;
198 using Item =
typename Src::ItemConstRef;
201 static constexpr inline IterValue<Item>
nextBack(SrcCRef<TContainer>& self) {
202 if(!Src::hasNext(self.container, self.iter)) [[unlikely]] {
return {}; }
203 return Src::nextBack(self.container, self.iter);
207 template<
typename TContainer>
208 struct trait::ExactSizeIterator<SrcCRef<TContainer>> {
209 static constexpr inline size_t size(
const SrcCRef<TContainer>& self) {
return self.container.size(); }
212 template<
typename TContainer>
213 requires util::ContiguousMemoryContainer<TContainer>
214 struct trait::ContiguousMemoryIterator<SrcCRef<TContainer>> {
215 using ItemPtr = std::add_pointer_t<std::remove_reference_t<typename SrcCRef<TContainer>::Item>>;
Public Iterator API surface.
Container that is used to pass elements through CXXIter's iterator pipelines.
CXXIter iterator source that immutably borrows the input item source, and passes immutable references...
CXXIter iterator source that takes over the input item source, and moves its items through the elemen...
CXXIter iterator source that mutably borrows the input item source, and passes mutable references to ...
Trait, that iterators implement whose elements are stored in a contiguous block of memory.
static constexpr ItemPtr currentPtr(typename trait::Iterator< T >::Self &self)=delete
Get the pointer of the current element.
std::add_pointer_t< std::remove_reference_t< typename Iterator< T >::Item > > ItemPtr
Pointer type to an item of this iterator.
Trait that extends the Iterator trait with double-ended functionality.
static constexpr IterValue< typename Iterator< T >::Item > nextBack(Self &self)=delete
Pull the next last element from the iterator pipeline previous to this pipeline-element.
Trait, that extends iterators for which an exact length is known.
static constexpr size_t size(const typename trait::Iterator< T >::Self &self)=delete
Get the iterator's exact number of elements.
Trait, that is used for the chaining and the operation of iterator pipelines.
static constexpr IterValue< Item > next(Self &self)=delete
Pull one element from the iterator pipeline previous to this pipeline-element.
void Item
Item-Type. This is the type of elements that can be pulled from this pipeline-element.
trait::Iterator< T > Self
Self-Type. This is the type of the struct for which the trait::Iterator is being specialized.
static constexpr SizeHint sizeHint(const Self &self)=delete
Get the bounds on the remaining length of the iterator pipeline until this pipeline-element,...
static constexpr size_t advanceBy(Self &self, size_t n)=delete
Advance the iterator by n elements.
Type of the state structure stored in CXXIter's source classes, used to keep track of the iteration p...
Type of the state structure stored in CXXIter's source classes, used to keep track of the iteration p...
SourceTrait, that is used by CXXIter's standard source classes CXXIter::SrcMov, CXXIter::SrcRef and C...
static constexpr ItemRef peekNext(TContainer &container, IteratorState &iter)
Return the next item in the iteration with the given iter state on the given container,...
static constexpr IteratorState initIterator(TContainer &container)
Return an initial IteratorState instance for iteration on the given container.