| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <tuple> | ||
| 4 | #include <type_traits> | ||
| 5 | |||
| 6 | #include "Common.h" | ||
| 7 | |||
| 8 | namespace CXXIter { | ||
| 9 | |||
| 10 | // ################################################################################################ | ||
| 11 | // INTO COLLECTOR | ||
| 12 | // ################################################################################################ | ||
| 13 | /** @private */ | ||
| 14 | template<typename TChainInput, typename TContainer> | ||
| 15 | struct IntoCollector {}; | ||
| 16 | /** @private */ | ||
| 17 | template<typename TChainInput, typename TContainer> | ||
| 18 | requires util::BackInsertableContainer<TContainer, typename TChainInput::ItemOwned> | ||
| 19 | struct IntoCollector<TChainInput, TContainer> { | ||
| 20 | using Item = typename TChainInput::Item; | ||
| 21 | |||
| 22 | 274 | static constexpr void collectInto(TChainInput& input, TContainer& container) { | |
| 23 | if constexpr(util::ReservableContainer<TContainer>) { | ||
| 24 |
2/4✓ Branch 3 taken 125 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 125 times.
✗ Branch 7 not taken.
|
250 | container.reserve( container.size() + input.sizeHint().expectedResultSize() ); |
| 25 | } | ||
| 26 | 1899 | input.forEach([&container](Item&& item) { container.push_back( std::forward<Item>(item) ); }); | |
| 27 | 272 | } | |
| 28 | }; | ||
| 29 | /** @private */ | ||
| 30 | template<typename TChainInput, typename TContainer> | ||
| 31 | requires (!util::BackInsertableContainer<TContainer, typename TChainInput::ItemOwned>) | ||
| 32 | && util::InsertableContainer<TContainer, typename TChainInput::ItemOwned> | ||
| 33 | struct IntoCollector<TChainInput, TContainer> { | ||
| 34 | using Item = typename TChainInput::Item; | ||
| 35 | |||
| 36 | 86 | static constexpr void collectInto(TChainInput& input, TContainer& container) { | |
| 37 | if constexpr(util::ReservableContainer<TContainer>) { | ||
| 38 |
2/4✓ Branch 3 taken 25 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 25 times.
✗ Branch 7 not taken.
|
50 | container.reserve( container.size() + input.sizeHint().expectedResultSize() ); |
| 39 | } | ||
| 40 | 206 | input.forEach([&container](Item&& item) { container.insert( std::forward<Item>(item) ); }); | |
| 41 | 86 | } | |
| 42 | }; | ||
| 43 | /** @private */ | ||
| 44 | template<typename TChainInput, typename TContainer> | ||
| 45 | requires util::StdArrayContainer<TContainer, typename TChainInput::ItemOwned> | ||
| 46 | struct IntoCollector<TChainInput, TContainer> { | ||
| 47 | using Item = typename TChainInput::Item; | ||
| 48 | |||
| 49 | 10 | static constexpr void collectInto(TChainInput& input, TContainer& container) { | |
| 50 | 10 | size_t idx = 0; | |
| 51 | input | ||
| 52 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | .take(container.max_size()) |
| 53 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
25 | .forEach([&idx, &container](Item&& item) { container[idx++] = item; }); |
| 54 | 10 | } | |
| 55 | }; | ||
| 56 | |||
| 57 | |||
| 58 | // ################################################################################################ | ||
| 59 | // COLLECTOR | ||
| 60 | // ################################################################################################ | ||
| 61 | /** @private */ | ||
| 62 | template<typename TChainInput, template <typename...> typename TContainer, typename... TContainerArgs> | ||
| 63 | struct Collector {}; | ||
| 64 | /** @private */ | ||
| 65 | template<typename TChainInput, template <typename...> typename TContainer, typename... TContainerArgs> | ||
| 66 | requires util::BackInsertableContainerTemplate<TContainer, typename TChainInput::ItemOwned, TContainerArgs...> | ||
| 67 | || util::InsertableContainerTemplate<TContainer, typename TChainInput::ItemOwned, TContainerArgs...> | ||
| 68 | struct Collector<TChainInput, TContainer, TContainerArgs...> { | ||
| 69 | template<typename Item, typename ItemOwned> | ||
| 70 | 262 | static constexpr TContainer<ItemOwned, TContainerArgs...> collect(TChainInput& input) { | |
| 71 | 262 | TContainer<ItemOwned, TContainerArgs...> container; | |
| 72 |
2/2✓ Branch 1 taken 130 times.
✓ Branch 2 taken 1 times.
|
262 | IntoCollector<TChainInput, decltype(container)>::collectInto(input, container); |
| 73 | 260 | return container; | |
| 74 | } | ||
| 75 | }; | ||
| 76 | /** @private */ | ||
| 77 | template<typename TChainInput, template <typename...> typename TContainer, typename... TContainerArgs> | ||
| 78 | requires (!util::BackInsertableContainerTemplate<TContainer, typename TChainInput::ItemOwned, TContainerArgs...>) | ||
| 79 | && util::is_pair<typename TChainInput::ItemOwned> | ||
| 80 | && util::AssocContainerTemplate<TContainer, std::tuple_element_t<0, typename TChainInput::ItemOwned>, std::tuple_element_t<1, typename TChainInput::ItemOwned>, TContainerArgs...> | ||
| 81 | struct Collector<TChainInput, TContainer, TContainerArgs...> { | ||
| 82 | template<typename Item, typename ItemOwned> | ||
| 83 | 20 | static constexpr auto collect(TChainInput& input) { | |
| 84 | using TKey = std::remove_const_t<std::tuple_element_t<0, typename TChainInput::ItemOwned>>; | ||
| 85 | using TValue = std::tuple_element_t<1, typename TChainInput::ItemOwned>; | ||
| 86 | 20 | TContainer<TKey, TValue, TContainerArgs...> container; | |
| 87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | IntoCollector<TChainInput, decltype(container)>::collectInto(input, container); |
| 88 | 20 | return container; | |
| 89 | } | ||
| 90 | }; | ||
| 91 | |||
| 92 | } | ||
| 93 |