Turns out that the final version of Boost.Coroutine that made it
into the 1.53 release has out-of-the-box support for treating the
values returned by a coroutine as a range, which makes writing such
an outputs_of() function trivial:
using boost::coroutines::coroutine;
...
template <typename T, typename F>
coroutine<T()> outputs_of(F f)
{
return coroutine<T()>{[f](typename coroutine<T()>::caller_type& caller)
{
f(boost::make_function_output_iterator([&caller](const T& t){ caller(t); }));
}};
}
A complete example using the two functions in your original post is
attached.
The code uses some C++11 features like lambdas, but these can
easily be translated to their C++03 equivalents if necessary.
I'll leave it to you as an exercise to do that if you need to.
Hope that helps!
Regards,
Nate