@@ -21,7 +21,7 @@ namespace fpgen {
2121 * \tparam Container The container type.
2222 * \param[in] cont The container to iterate over.
2323 * \returns A new generator which will iterate over the container.
24- * \see fpgen::from_tup
24+ * \see fpgen::from_tup, fpgen::enumerate
2525 */
2626template <typename T, typename ... TArgs,
2727 template <typename ...> typename Container>
@@ -31,6 +31,31 @@ generator<T> from(const Container<T, TArgs...> &cont) {
3131 }
3232}
3333
34+ /* *
35+ * \brief Creates a generator over a data source, with indexing.
36+ *
37+ * The data source does not have to allow indexing, but it is recommended for
38+ * repeatable behaviour. If the index is not needed, use fpgen::from. The data
39+ * source should support iterating (using `std::begin` and `std::end`).
40+ *
41+ * \tparam T The type contained in the container.
42+ * \tparam TArgs Any other template parameters passed to the container.
43+ * \tparam Container The container type.
44+ * \param[in] cont The container to iterate over.
45+ * \returns A new generator which will iterate over the container using index
46+ * and value.
47+ * \see fpgen::from_tup, fpgen::enumerate
48+ */
49+ template <typename T, typename ... TArgs,
50+ template <typename ...> typename Container>
51+ generator<std::tuple<size_t , T>> enumerate(const Container<T, TArgs...> &cont) {
52+ size_t i = 0 ;
53+ for (auto it = std::begin (cont); it != std::end (cont); ++it) {
54+ co_yield {i, *it};
55+ i++;
56+ }
57+ }
58+
3459/* *
3560 * \brief Creates a generator over an associative data source.
3661 *
0 commit comments