| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <utility> | ||
| 4 | |||
| 5 | #include "../Common.h" | ||
| 6 | #include "../util/TraitImpl.h" | ||
| 7 | |||
| 8 | namespace CXXIter { | ||
| 9 | |||
| 10 | // ################################################################################################ | ||
| 11 | // MAP | ||
| 12 | // ################################################################################################ | ||
| 13 | namespace op { | ||
| 14 | /** @private */ | ||
| 15 | template<typename TChainInput, typename TMapFn, typename TItem> | ||
| 16 | class [[nodiscard(CXXITER_CHAINER_NODISCARD_WARNING)]] Map : public IterApi<Map<TChainInput, TMapFn, TItem>> { | ||
| 17 | friend struct trait::Iterator<Map<TChainInput, TMapFn, TItem>>; | ||
| 18 | friend struct trait::DoubleEndedIterator<Map<TChainInput, TMapFn, TItem>>; | ||
| 19 | friend struct trait::ExactSizeIterator<Map<TChainInput, TMapFn, TItem>>; | ||
| 20 | private: | ||
| 21 | TChainInput input; | ||
| 22 | TMapFn mapFn; | ||
| 23 | public: | ||
| 24 | 335 | constexpr Map(TChainInput&& input, TMapFn mapFn) : input(std::move(input)), mapFn(mapFn) {} | |
| 25 | }; | ||
| 26 | } | ||
| 27 | // ------------------------------------------------------------------------------------------------ | ||
| 28 | /** @private */ | ||
| 29 | template<typename TChainInput, typename TMapFn, typename TItem> | ||
| 30 | struct trait::Iterator<op::Map<TChainInput, TMapFn, TItem>> { | ||
| 31 | using ChainInputIterator = trait::Iterator<TChainInput>; | ||
| 32 | using InputItemOwned = typename TChainInput::ItemOwned; | ||
| 33 | // CXXIter Interface | ||
| 34 | using Self = op::Map<TChainInput, TMapFn, TItem>; | ||
| 35 | using Item = TItem; | ||
| 36 | |||
| 37 | 974 | static constexpr inline IterValue<Item> next(Self& self) { | |
| 38 |
1/2✓ Branch 1 taken 490 times.
✗ Branch 2 not taken.
|
974 | auto item = ChainInputIterator::next(self.input); |
| 39 |
1/2✓ Branch 1 taken 490 times.
✗ Branch 2 not taken.
|
1948 | return item.template map<Item, TMapFn&>(self.mapFn); |
| 40 | } | ||
| 41 | 250 | static constexpr inline SizeHint sizeHint(const Self& self) { return ChainInputIterator::sizeHint(self.input); } | |
| 42 | 49 | static constexpr inline size_t advanceBy(Self& self, size_t n) { return util::advanceByPull(self, n); } | |
| 43 | }; | ||
| 44 | /** @private */ | ||
| 45 | template<CXXIterDoubleEndedIterator TChainInput, typename TMapFn, typename TItem> | ||
| 46 | struct trait::DoubleEndedIterator<op::Map<TChainInput, TMapFn, TItem>> { | ||
| 47 | using ChainInputIterator = trait::DoubleEndedIterator<TChainInput>; | ||
| 48 | using InputItemOwned = typename TChainInput::ItemOwned; | ||
| 49 | // CXXIter Interface | ||
| 50 | using Self = op::Map<TChainInput, TMapFn, TItem>; | ||
| 51 | using Item = TItem; | ||
| 52 | |||
| 53 | 21 | static constexpr inline IterValue<Item> nextBack(Self& self) { | |
| 54 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
21 | auto item = ChainInputIterator::nextBack(self.input); |
| 55 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
42 | return item.template map<Item, TMapFn&>(self.mapFn); |
| 56 | } | ||
| 57 | }; | ||
| 58 | /** @private */ | ||
| 59 | template<CXXIterExactSizeIterator TChainInput, typename TMapFn, typename TItem> | ||
| 60 | struct trait::ExactSizeIterator<op::Map<TChainInput, TMapFn, TItem>> { | ||
| 61 | static constexpr inline size_t size(const op::Map<TChainInput, TMapFn, TItem>& self) { return trait::ExactSizeIterator<TChainInput>::size(self.input); } | ||
| 62 | }; | ||
| 63 | |||
| 64 | } | ||
| 65 |