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