| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- //
- // RecursiveExpander.h
- // iterator
- //
- // Created by Sam Jaffe on 9/23/25.
- // Copyright © 2025 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <iterator>
- #include <type_traits>
- #include <iterator/concepts.h>
- #include <iterator/detail/projection_tuple.h>
- #include <iterator/end_aware_iterator.h>
- namespace iterator::detail {
- template <typename Proj, typename It, size_t I>
- using projection_t = std::invoke_result_t<Proj, std::iter_reference_t<It>,
- std::integral_constant<size_t, I>>;
- template <typename It, typename Projs, typename MaxDepth, size_t N = 0,
- typename V = std::decay_t<projection_t<Projs, It, N>>>
- struct RecursiveExpander {
- using type = std::tuple<EndAwareIterator<It>>;
- };
- template <typename It, typename Projs, size_t N>
- struct RecursiveExpander<It, Projs, bounded<N + 1>, N> {
- using type = std::tuple<EndAwareIterator<It>>;
- };
- template <typename It, typename Projs, typename MaxDepth, size_t N, Range V>
- struct RecursiveExpander<It, Projs, MaxDepth, N, V> {
- using projected_value_type = projection_t<Projs, It, N>;
- using expand_next = RecursiveExpander<iterator_t<projected_value_type>, Projs,
- MaxDepth, N + 1>;
- using type =
- tuple_cat_t<std::tuple<EndAwareIterator<It>>, typename expand_next::type>;
- };
- template <typename It, typename Projs, typename MaxDepth, size_t N,
- AssocRange V>
- struct RecursiveExpander<It, Projs, MaxDepth, N, V> {
- using projected_value_type =
- std::tuple_element_t<1,
- std::remove_reference_t<projection_t<Projs, It, N>>>;
- using expand_next = RecursiveExpander<iterator_t<projected_value_type>, Projs,
- MaxDepth, N + 1>;
- using type =
- tuple_cat_t<std::tuple<EndAwareIterator<It>>, typename expand_next::type>;
- };
- }
|