ソースを参照

Expand iterator_fwd.hpp

Sam Jaffe 4 年 前
コミット
0195845188
2 ファイル変更31 行追加40 行削除
  1. 15 2
      include/iterator/iterator_fwd.hpp
  2. 16 38
      include/iterator/recursive_iterator.hpp

+ 15 - 2
include/iterator/iterator_fwd.hpp

@@ -9,7 +9,20 @@
 
 #include <cstdlib>
 
+namespace iterator::recursive {
+  struct unbounded;
+  template <size_t N, size_t I = 1> struct bounded;
+  template <typename Iter, typename = unbounded> class rimpl;
+}
+
 namespace iterator {
-  template <typename Iterator> class end_aware_iterator;
-  template <typename MetaIterator> class joining_iterator;
+  template <typename Iter> class end_aware_iterator;
+  template <typename Iter> class filter_iterator;
+  template <typename Iter> class joining_iterator;
+  template <typename Iter> class unkeyed_iterator;
+  template <typename... Iters> class zip_iterator;
+
+  template <typename Iter> using recursive_iterator = recursive::rimpl<Iter>;
+  template <typename Iter, std::size_t N>
+  using recursive_iterator_n = recursive::rimpl<Iter, recursive::bounded<N>>;
 }

+ 16 - 38
include/iterator/recursive_iterator.hpp

@@ -18,7 +18,7 @@
 #include "facade.h"
 
 namespace iterator::recursive {
-  template <size_t N, size_t I = 1> struct bounded {
+  template <size_t N, size_t I> struct bounded {
     template <typename It>
     static constexpr recursion_type const value =
         I == N ? recursion_type::END : typeclass_t<It>::value;
@@ -68,7 +68,21 @@ namespace iterator::recursive {
     auto get(It iter) const { return std::tie(iter->first); };
   };
 
-  template <typename It, typename Bnd = unbounded>
+  /**
+   * @brief An iterator type for nested collections, allowing you to treat it as
+   * a single-layer collection.
+   *
+   * In order to provide a simple interface, if an associative container is used
+   * in the chain, the type returned by operator*() is a tuple. If multiple
+   * associative containers are nested, then the tuple will be of the form
+   * std::tuple<key1, key2, ..., keyN, value>. To avoid copies, and allow
+   * editting of underlying values, the tuple contains references.
+   *
+   * @tparam It The iterator type of the top-level collection.
+   * @tparam Bnd The bounding type, representing how many layers this iterator
+   * is willing to delve in the parent object.
+   */
+  template <typename It, typename Bnd>
   class rimpl : public facade<rimpl<It, Bnd>> {
   private:
     typename tuple<It, Bnd>::iter impl_;
@@ -161,42 +175,6 @@ namespace iterator::recursive {
 
 MAKE_ITERATOR_FACADE_TYPEDEFS_T(::iterator::recursive::rimpl);
 
-namespace iterator {
-  /**
-   * @brief An iterator type for nested collections, allowing you to treat it as
-   * a single-layer collection.
-   *
-   * In order to provide a simple interface, if an associative container is used
-   * in the chain, the type returned by operator*() is a tuple. If multiple
-   * associative containers are nested, then the tuple will be of the form
-   * std::tuple<key1, key2, ..., keyN, value>. To avoid copies, and allow
-   * editting of underlying values, the tuple contains references.
-   *
-   * @tparam It The iterator type of the top-level collection.
-   */
-  template <typename It> using recursive_iterator = recursive::rimpl<It>;
-
-  /**
-   * @copydoc recursive_iterator
-   * This object has bounded recursive depth, so that it can be used to get
-   * sub-collections, which may be used in other functions.
-   *
-   * For Example:
-   * @code
-   * using map_type = std::map<std::string, std::map<std::string,
-   * std::vector<Data> > >;
-   * ...
-   * recursive_iterator_n<map_type::iterator, 2> iter{ ... };
-   * std::vector<Data> & data = std::get<2>(*iter);
-   * reload_data_from_file( std::get<1>(*iter), data );
-   * @endcode
-   *
-   * @tparam N The maximum depth to recurse into the object
-   */
-  template <typename It, std::size_t N>
-  using recursive_iterator_n = recursive::rimpl<It, recursive::bounded<N>>;
-}
-
 namespace std {
   template <std::size_t I, typename It>
   auto get(::iterator::recursive_iterator<It> const & iter) {