6#include "../util/TraitImpl.h"
15 template<
typename TChainInput>
16 class [[nodiscard(CXXITER_CHAINER_NODISCARD_WARNING)]] FlagLast :
public IterApi<FlagLast<TChainInput>> {
17 friend struct trait::Iterator<FlagLast<TChainInput>>;
18 friend struct trait::DoubleEndedIterator<FlagLast<TChainInput>>;
19 friend struct trait::ExactSizeIterator<FlagLast<TChainInput>>;
21 using InputItem =
typename TChainInput::Item;
24 bool initialized =
false;
25 IterValue<InputItem> nextValue;
27 constexpr FlagLast(TChainInput&& input) : input(std::move(input)) {}
32 template<
typename TChainInput>
33 struct trait::Iterator<op::FlagLast<TChainInput>> {
34 using ChainInputIterator = trait::Iterator<TChainInput>;
35 using InputItem =
typename TChainInput::Item;
37 using Self = op::FlagLast<TChainInput>;
38 using Item = std::pair<InputItem, bool>;
40 static constexpr inline IterValue<Item> next(Self& self) {
41 if(!self.initialized) [[unlikely]] {
43 self.nextValue = ChainInputIterator::next(self.input);
44 self.initialized =
true;
47 if(!self.nextValue.has_value()) [[unlikely]] {
return {}; }
51 Item item = { std::forward<InputItem>(self.nextValue.value()),
false };
52 self.nextValue = ChainInputIterator::next(self.input);
53 item.second = !self.nextValue.has_value();
56 static constexpr inline SizeHint sizeHint(
const Self& self) {
return ChainInputIterator::sizeHint(self.input); }
57 static constexpr inline size_t advanceBy(Self& self,
size_t n) {
return util::advanceByPull(self, n); }
60 template<CXXIterExactSizeIterator TChainInput>
61 struct trait::ExactSizeIterator<op::FlagLast<TChainInput>> {
62 static constexpr inline size_t size(
const op::FlagLast<TChainInput>& self) {
return trait::ExactSizeIterator<TChainInput>::size(self.input); }