chaining functions input output

Hello, i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory? http://codepad.org/tTwkUQhp Rds, MM

i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory?
No. You have to supply a range [begin..end) for fun2(), so this range should be prepared first.

someone mentioned boost.coroutine could help in this case?
On 19 September 2012 11:04, Igor R
i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory?
No. You have to supply a range [begin..end) for fun2(), so this range should be prepared first. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 19 September 2012 11:04, Igor R
wrote: i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory?
No. You have to supply a range [begin..end) for fun2(), so this range should be prepared first.
someone mentioned boost.coroutine could help in this case?
Not with the signatures you specified. If *you* define and implement these templates (i.e. they are not from a 3d party), and you want to adjust their signatures and implementations to make them a generator/coroutine, then maybe it's feasible... http://ok73.ok.funpic.de/boost/libs/coroutine/doc/html/

i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory?
No. You have to supply a range [begin..end) for fun2(), so this range should be prepared first.
someone mentioned boost.coroutine could help in this case?
I'm the one who mentioned that, and yes, it is possible :) Basically, one can use coroutines to implement a generic outputs_of() function that takes a unary function whose argument is an output iterator, and returns a range representing all the values passed to this output iterator, without storing them all. You would call it like this: fun2(outputs_of(bind(fun1, input, _1)), output) I actually wrote such a function, but using an earlier version of the coroutine library (back when the coroutine functionality was still in Boost.Context). I am planning to update my implementation after the interface of Boost.Coroutine is stabilized (it is currently under review on the dev list). I am happy to post it once I've done that, but in the meantime here's the general idea: - outputs_of(f) creates a coroutine c whose body calls f with an output iterator which yields the outputted value - begin() of the resulting range starts the coroutine and saves the first yielded value - dereference() of the begin iterator returns the saved value - increment() of the begin iterator re-enters the coroutine and saves the next yielded value - when the coroutine is finished a flag is set to that the begin and end iterators return true Hope that helps! Regards, Nate

i have these 2 functions provided to me and I wonder whether they can somehow be chained without using intermediary memory?
No. You have to supply a range [begin..end) for fun2(), so this range should be prepared first.
someone mentioned boost.coroutine could help in this case?
I'm the one who mentioned that, and yes, it is possible :)
Basically, one can use coroutines to implement a generic outputs_of() function that takes a unary function whose argument is an output iterator, and returns a range representing all the values passed to this output iterator, without storing them all.
You would call it like this:
fun2(outputs_of(bind(fun1, input, _1)), output)
I actually wrote such a function, but using an earlier version of the coroutine library (back when the coroutine functionality was still in Boost.Context). I am planning to update my implementation after the interface of Boost.Coroutine is stabilized (it is currently under review on the dev list). I am happy to post it once I've done that
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

2013/2/18 Nathan Ridge
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
coroutine outputs_of(F f) { return coroutine {[f](typename coroutine ::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

thanks Oliver,Nate,
I will deploy this once is 1.54 is released,
MM
On 19 February 2013 08:05, Oliver Kowalke
2013/2/18 Nathan Ridge
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
coroutine outputs_of(F f) { return coroutine {[f](typename coroutine ::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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Igor R
-
MM
-
Nathan Ridge
-
Oliver Kowalke