recursive_iterator_base.hpp 1008 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include "../end_aware_iterator.hpp"
  3. #include "recursive_iterator_traits.hpp"
  4. namespace iterator::detail {
  5. /**
  6. * @class recursive_iterator_base
  7. * @brief A thin wrapper around end_aware_iterator for the purposes of
  8. * template metaprogramming.
  9. */
  10. template <typename Iterator>
  11. class recursive_iterator_base : public end_aware_iterator<Iterator> {
  12. public:
  13. using super = end_aware_iterator<Iterator>;
  14. protected:
  15. using recursive_category =
  16. std::conditional_t<detail::is_associative<Iterator>{},
  17. continue_layer_tag_t, terminal_layer_tag_t>;
  18. public:
  19. using super::super;
  20. recursive_iterator_base(super const & iter) : super(iter) {}
  21. recursive_iterator_base(super && iter) : super(std::move(iter)) {}
  22. protected:
  23. decltype(auto) get() const {
  24. if constexpr (detail::is_associative<Iterator>{}) {
  25. return std::tie((**this).first, (**this).second);
  26. } else {
  27. return **this;
  28. }
  29. }
  30. };
  31. }