I'm looking to implement something similar to the deferred IEnumerable concept in C++, but without template implementations. (My question is very similar to this other question, except for the deal-breaking templates.)
In our code, we have many functions that receive a spec to query and will store the results in a passed std::vector&. Often these functions call lower level versions which do their own filtering and combining with other sets. Sometimes they will create local vectors (with a different temp allocator) to call the lower-level functions, then push_back to the caller's vector after filtering that. These are not generic functions, in either word or spirit.
I'm looking to eliminate the copies and allocs, and even the need for a results container. Plus while I'm doing this, I'd like to give it a short-circuit ability.
There's an obvious need for deferred operations here. In C#, this would be easy. Everything yields into an IEnumerable, and use the Where() etc. operators, all deferred.
I have an idea how to do this in C++, passing in callbacks rather than containers. We just need the "push_back" abstracted, plus a returned bool for "stop here". The callbacks would be chained very similarly to IEnumerable operators, though in operation it would be more of a push-pull, and maybe feel a bit like IObservable.
And on top of all this, I have to avoid templatizing these function implementations. I don't want to refactor a lot of code, and I don't want to run into unsupported compiler surprises on the 15 or so different platforms we're currently compiling to. So no promises, no (I think). And no C++11.
This seems like a solved problem, but I've poked around on Google and maybe haven't found the right way to ask it. Has this problem been solved already?