In C++, what is the best way to return a collection to client code without using iterators.
Let's say iterators are ruled out because eg the collection is remote. I'd like a signature for a function that returns the collection in the most useful form possible.
By 'best', I mean the best trade-off between clarity and genericity.
My instinct was (where result.push_back(obj) is valid C++):
template <typename T>
void getCollection(T& result);
I wonder if anyone has better ideas, for example that would also support insertions into containers that do not support push_back, or that require transformation of the objects in the collection.
The following, perhaps?
template <typename Func>
void getCollection(Func f); // applies f to all the objects