7#include "../sources/ContainerSources.h"
8#include "../util/TraitImpl.h"
17 template<
typename TChainInput,
typename TFlatMapFn,
typename TItemContainer>
18 requires (!std::is_reference_v<TItemContainer>)
19 class [[nodiscard(CXXITER_CHAINER_NODISCARD_WARNING)]] FlatMap :
public IterApi<FlatMap<TChainInput, TFlatMapFn, TItemContainer>> {
20 friend struct trait::Iterator<FlatMap<TChainInput, TFlatMapFn, TItemContainer>>;
23 std::optional<SrcMov<TItemContainer>> current;
26 constexpr FlatMap(TChainInput&& input, TFlatMapFn mapFn) : input(std::move(input)), mapFn(mapFn) {}
31 template<
typename TChainInput,
typename TFlatMapFn,
typename TItemContainer>
32 struct trait::Iterator<op::FlatMap<TChainInput, TFlatMapFn, TItemContainer>> {
33 using NestedChainIterator = trait::Iterator<SrcMov<TItemContainer>>;
34 using ChainInputIterator = trait::Iterator<TChainInput>;
35 using InputItem =
typename ChainInputIterator::Item;
37 using Self = op::FlatMap<TChainInput, TFlatMapFn, TItemContainer>;
38 using Item =
typename TItemContainer::value_type;
40 static constexpr inline IterValue<Item>
next(
Self& self) {
43 auto item = ChainInputIterator::next(self.input);
44 if(!item.has_value()) [[unlikely]] {
return {}; }
45 self.current = SrcMov(std::move(
46 self.mapFn(std::forward<InputItem>( item.value() ))
51 auto item = NestedChainIterator::next(*self.current);
52 if(item.has_value()) [[likely]] {
59 static constexpr inline SizeHint
sizeHint(
const Self&) {
return SizeHint(); }
60 static constexpr inline size_t advanceBy(
Self& self,
size_t n) {
return util::advanceByPull(self, n); }
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.