template function to change container

I find myself changing containers a lot. Can someone show me how to write a template function to carry out something like this:
1
2
3
std::set<A> mySet;
for (std::list<A>::iterator it = myList.begin(); it != myList.end(); ++it)
    mySet.emplace (*it);

Last edited on
What would be the desired effect of calling such function? It is specified to take both containers by value and return nothing.

(after the OP edit)
why not just construct directly: std::set<A> mySet(myList.begin(), myList.end()); ?
Last edited on
Ok, this is an example I want to do with just one line:

1
2
3
std::set<A> mySet;
for (std::list<A>::iterator it = myList.begin(); it != myList.end(); ++it)
    mySet.emplace (*it);


How to write a function to do this with all possible container changes?
Last edited on
<algorithm>
<iterator>
 
std::copy(Container1.begin(), Container1.end(), std::inserter(Container2, Iterator));
Topic archived. No new replies allowed.