7#include "../util/TraitImpl.h"
16 template<
typename TChainInput,
typename TSkipPredicate>
17 class [[nodiscard(CXXITER_CHAINER_NODISCARD_WARNING)]] SkipWhile :
public IterApi<SkipWhile<TChainInput, TSkipPredicate>> {
18 friend struct trait::Iterator<SkipWhile<TChainInput, TSkipPredicate>>;
21 TSkipPredicate skipPredicate;
22 bool skipEnded =
false;
24 constexpr SkipWhile(TChainInput&& input, TSkipPredicate skipPredicate) : input(std::move(input)), skipPredicate(skipPredicate) {}
29 template<
typename TChainInput,
typename TSkipPredicate>
30 struct trait::Iterator<op::SkipWhile<TChainInput, TSkipPredicate>> {
31 using ChainInputIterator = trait::Iterator<TChainInput>;
32 using InputItem =
typename TChainInput::Item;
34 using Self = op::SkipWhile<TChainInput, TSkipPredicate>;
35 using Item = InputItem;
37 static constexpr inline IterValue<Item> next(Self& self) {
39 auto item = ChainInputIterator::next(self.input);
40 if(!item.has_value()) [[unlikely]] {
return {}; }
41 if(self.skipEnded) {
return item; }
42 if(!self.skipPredicate(item.value())) {
43 self.skipEnded =
true;
48 static constexpr inline SizeHint sizeHint(
const Self& self) {
49 SizeHint input = ChainInputIterator::sizeHint(self.input);
50 return SizeHint(0, input.upperBound);
52 static constexpr inline size_t advanceBy(Self& self,
size_t n) {
return util::advanceByPull(self, n); }