Function templates for arbitrary STL containers containing arbitrary types.
Posted
by Chad Brewbaker
on Stack Overflow
See other posts from Stack Overflow
or by Chad Brewbaker
Published on 2010-05-18T18:43:45Z
Indexed on
2010/05/18
18:50 UTC
Read the original article
Hit count: 215
I have an arbitrary STL container C, which contains elements of an arbitrary type T. I want to create an std::vector that has a copy of all the elements. What is the cleanest way to do this?
template <typename C>
void myfunction(C container){
/*Derive the type T of elements within the container*/
std::vector<T> mystack;
/* Iterate over container and push_back() the elements into mystack*/
}
© Stack Overflow or respective owner