   saving content from stl?
  im trying to write a function that takes any of the stl-containers (vector, deque and list) and saves all the elements...does all of the inherit from a common class or do i have to use templates? or is there any baseclass for all iterators i could use? trying googling a bit but didnt find anything :/ 
  the normal way would be to pass the iterators to a templated function. if you're going to save every item in the container you might as well use the std::for_each function and pass it a function object which will put the contents into the stream, database, whatever it is you're serialising to.read the sgi.com/tech/stl docsedit: The containers don't inherit. Some of the iterators might but it's only for the interface. They don't make use of polymorphism. There are certain requirements that the containers and iterators conform to which make them work together well. For example iterator will have a typedef called value_type in the iterator_traits.   [edited by - petewood on February 2, 2004 8:56:30 AM];#include <iterator>// has input_iterator#include <algorithm>// has copycopy(v.begin(), v.end(),ostream_iterator(cout, "/n"));  specifically, look up ostream_iteratoron google ;quote:They don''t make use of polymorphism.Yes they do.  They use both parametric and overload polymorphism.  They might even use coercion polymorphism.What they don''t use is inclusion polymorphism.  But this is not the same as "not making use of polymorphism".;quote:Original post by DrPizza  quote:They don''t make use of polymorphism.Yes they do.  They use both parametric and overload polymorphism.  They might even use coercion polymorphism.What they don''t use is inclusion polymorphism.  But this is not the same as "not making use of polymorphism". Thanks for being pedantic for me, Dr. Pizza. I meant runtime polymorphism. ;  :D ;  Something like this? void save(string s){cout <<stuff <<endl;}template <class ita>void saveSTL(ita start, ita end){    for_each(start,end,save);}void main(){vector<string> v;v.push_back(string("a");v.push_back(string("b");v.push_back(string("c");v.push_back(string("d");saveSTL(v.begin(),v.end());} reality is only an option   [edited by - dathui on February 3, 2004 5:30:30 AM] [edited by - dathui on February 3, 2004 5:30:55 AM] [edited by - dathui on February 3, 2004 5:32:25 AM];void main(){vector<string> v;v.push_back(string("a");v.push_back(string("b");v.push_back(string("c");v.push_back(string("d");copy(v.begin(), v.end(),ostream_iterator(cout, " ")); } That doesn''t even care if they are strings!  As long as cout is replaced by a ostream...even one you define! (like a file or buffer).The " " could be replaced by anthing you want in between them. 