| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // unkeyed_iterator.hpp
- // iterator
- //
- // Created by Sam Jaffe on 2/20/17.
- //
- #pragma once
- #include "facade.h"
- #include <iterator>
- namespace iterator {
- /**
- * At first glance, this class seems like it acts as an iterator that would be
- * used in the C++ equivalent of Java's Map::values() function. However,
- * notices that we do not assume that the input iterator is a map iterator.
- * The useful feature of this iterator - and the source of its name - is its
- * ability to be composed with recursive_iterator. This means that you can
- * have something crazy like a four-level map and then do:
- * \code
- * std::map<int, std::map<std::string, std::map<int, BigType>>> object;
- * auto const rit = make_recursive_iterator(object);
- * for (unkeyed_iterator<decltype(rit)> it = rit, end = {}; it != end; ++it) {
- * // Process only BigType, discarding all of the keys that we need to walk
- * }
- * \endcode
- */
- template <typename Iterator>
- class unkeyed_iterator : public facade<unkeyed_iterator<Iterator>> {
- private:
- static constexpr std::size_t const value_index =
- std::tuple_size<typename Iterator::value_type>::value - 1;
- public:
- unkeyed_iterator() = default;
- unkeyed_iterator(Iterator it) : base(it) {}
- decltype(auto) dereference() const { return std::get<value_index>(*base); }
- void increment() { ++base; }
- void decrement() { --base; }
- bool equal_to(unkeyed_iterator const & other) const {
- return base == other.base;
- }
- private:
- Iterator base;
- };
- }
- MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::unkeyed_iterator)
|