14 template<
typename TChainInput,
typename TContainer>
15 struct IntoCollector {};
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;
22 static constexpr void collectInto(TChainInput& input, TContainer& container) {
23 if constexpr(util::ReservableContainer<TContainer>) {
24 container.reserve( container.size() + input.sizeHint().expectedResultSize() );
26 input.forEach([&container](Item&& item) { container.push_back( std::forward<Item>(item) ); });
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;
36 static constexpr void collectInto(TChainInput& input, TContainer& container) {
37 if constexpr(util::ReservableContainer<TContainer>) {
38 container.reserve( container.size() + input.sizeHint().expectedResultSize() );
40 input.forEach([&container](Item&& item) { container.insert( std::forward<Item>(item) ); });
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;
49 static constexpr void collectInto(TChainInput& input, TContainer& container) {
52 .take(container.max_size())
53 .forEach([&idx, &container](Item&& item) { container[idx++] = item; });
62 template<
typename TChainInput,
template <
typename...>
typename TContainer,
typename... TContainerArgs>
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 static constexpr TContainer<ItemOwned, TContainerArgs...> collect(TChainInput& input) {
71 TContainer<ItemOwned, TContainerArgs...> container;
72 IntoCollector<TChainInput,
decltype(container)>::collectInto(input, container);
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 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 TContainer<TKey, TValue, TContainerArgs...> container;
87 IntoCollector<TChainInput,
decltype(container)>::collectInto(input, container);