@@ -202,6 +202,17 @@ template <typename T, typename Fun> void foreach (generator<T> gen, Fun func) {
202202 }
203203}
204204
205+ /* *
206+ * \brief Sends each value to the stream.
207+ *
208+ * Calls `stream << value` for each value in the generator, then returns the
209+ * resulting (modified) stream.
210+ *
211+ * \tparam T The type of values in the stream.
212+ * \param[in,out] gen The generator supplying the values.
213+ * \param[in,out] stream The stream to output to.
214+ * \returns The resulting stream.
215+ */
205216template <typename T>
206217std::ostream &to_stream (generator<T> gen, std::ostream &stream) {
207218 while (gen) {
@@ -210,6 +221,21 @@ std::ostream &to_stream(generator<T> gen, std::ostream &stream) {
210221 return stream;
211222}
212223
224+ /* *
225+ * \brief Sends each value to the stream. Values are separated by the given
226+ * separator.
227+ *
228+ * Calls `stream << value` for each value in the generator, then returns the
229+ * resulting (modified) stream. Between each pair of values in the generator,
230+ * the separator is added.
231+ *
232+ * \tparam T The type of values in the stream.
233+ * \tparam T2 The type of the separator.
234+ * \param[in,out] gen The generator supplying the values.
235+ * \param[in,out] stream The stream to output to.
236+ * \param[in] separator The separator to use.
237+ * \returns The resulting stream.
238+ */
213239template <typename T, typename T2>
214240std::ostream &to_stream (generator<T> gen, std::ostream &stream, T2 separator) {
215241 if (gen) {
@@ -221,6 +247,18 @@ std::ostream &to_stream(generator<T> gen, std::ostream &stream, T2 separator) {
221247 return stream;
222248}
223249
250+ /* *
251+ * \brief Sends each value to the stream on a separate line.
252+ *
253+ * Calls `stream << value << std::endl` for each value in the generator, then
254+ * returns the resulting (modified) stream. To avoid a trailing newline, see
255+ * `fpgen::to_lines_no_trail`
256+ *
257+ * \tparam T The type of values in the stream.
258+ * \param[in,out] gen The generator supplying the values.
259+ * \param[in,out] stream The stream to output to.
260+ * \returns The resulting stream.
261+ */
224262template <typename T>
225263std::ostream &to_lines (generator<T> gen, std::ostream &stream) {
226264 while (gen) {
@@ -229,6 +267,18 @@ std::ostream &to_lines(generator<T> gen, std::ostream &stream) {
229267 return stream;
230268}
231269
270+ /* *
271+ * \brief Sends each value to the stream on a separate line, without trailing
272+ * newline.
273+ *
274+ * Calls `stream << std::endl << value` for each value in the generator (except
275+ * the first), then returns the resulting (modified) stream.
276+ *
277+ * \tparam T The type of values in the stream.
278+ * \param[in,out] gen The generator supplying the values.
279+ * \param[in,out] stream The stream to output to.
280+ * \returns The resulting stream.
281+ */
232282template <typename T>
233283std::ostream &to_lines_no_trail (generator<T> gen, std::ostream &stream) {
234284 if (gen) {
0 commit comments