| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //
- // unkeyed_iterator.h
- // iterator
- //
- // Created by Sam Jaffe on 2/20/17.
- //
- #pragma once
- #include <iterator/forwards.h>
- #include <iterator/proxy.h>
- 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 = RecursiveIterator(object);
- * for (ValuesIterator<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 ValuesIterator : public Proxy<Iterator, ValuesIterator<Iterator>> {
- public:
- using Proxy<Iterator, ValuesIterator<Iterator>>::Proxy;
- decltype(auto) dereference() const {
- using value_type = typename Iterator::value_type;
- constexpr auto index = std::tuple_size<value_type>::value - 1;
- return std::get<index>(*this->impl());
- }
- };
- template <typename It> ValuesIterator(It) -> ValuesIterator<It>;
- }
|