Boost logo

Boost Users :

Subject: Re: [Boost-users] chaining functions input output
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2013-02-19 03:05:53


2013/2/18 Nathan Ridge <zeratul976_at_[hidden]>

> 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
>

boost.coroutine required some fixes releated C++11 and iterators (thank you
nate) - the fixes are applied to trunk and should be available in
boost-1.54.
Oliver



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net