8#include "../util/TraitImpl.h"
17 template<
typename TChainInput,
typename TTakePredicate>
18 class [[nodiscard(CXXITER_CHAINER_NODISCARD_WARNING)]] TakeWhile :
public IterApi<TakeWhile<TChainInput, TTakePredicate>> {
19 friend struct trait::Iterator<TakeWhile<TChainInput, TTakePredicate>>;
22 TTakePredicate takePredicate;
24 constexpr TakeWhile(TChainInput&& input, TTakePredicate takePredicate) : input(std::move(input)), takePredicate(takePredicate) {}
29 template<
typename TChainInput,
typename TTakePredicate>
30 struct trait::Iterator<op::TakeWhile<TChainInput, TTakePredicate>> {
31 using ChainInputIterator = trait::Iterator<TChainInput>;
32 using InputItem =
typename TChainInput::Item;
34 using Self = op::TakeWhile<TChainInput, TTakePredicate>;
35 using Item = InputItem;
37 static constexpr inline IterValue<Item> next(Self& self) {
38 auto item = ChainInputIterator::next(self.input);
39 if(!item.has_value()) [[unlikely]] {
return {}; }
41 if(self.takePredicate(item.value()) ==
false) {
return {}; }
44 static constexpr inline SizeHint sizeHint(
const Self& self) {
45 SizeHint input = ChainInputIterator::sizeHint(self.input);
46 return SizeHint(0, input.upperBound);
48 static constexpr inline size_t advanceBy(Self& self,
size_t n) {
return util::advanceByPull(self, n); }