
I have a function that transforms a serie of numbers into another serie:
template
void transform( InputIterator begin, InputIterator end, OutputIterator out ) { } and a 2nd function that calculates the standard deviation of a sample
template <typename InputIterator > double stdev( InputIterator begin, InputIterator end) { }
Is there a way to chain these existing functions in order to get the std dev of the transformed serie, without storing the intermediate numbers? Maybe with the help of some lazy iterator, or some lazy function?
In this particular case, you can use boost::transform_iterator rather than std::transform, as Jeff pointed out. However, this does not resolve the problem in general, which is how to treat the sequence of values a function writes to an output iterator as a range (or pair of iterators) input to another function (without accumulating the elements in a container, of course). This seems like a textbook use case for coroutines. I wonder whether a solution using Boost.Context would impose sufficiently little overhead to provide a general solution to this problem. Regards, Nate