The way it works STLis to accept pattern iterators to start and end the range that you want to process. When elements are to be inserted as a whole, a special insert iterator can be used.
template<typename InsertIter>
bool getValues(const std::string& query, InsertIter inserter) {
for(int i = 0; i < 6; ++i)
inserter = i;
}
Use it like this:
std::vector<int> v;
getValues("", std::back_inserter(v));
std::set<int> s;
getValues("", std::inserter(s, s.end()));
source
share