c++ - Function templates for arbitrary STL containers containing arbitrary types -


I have an arbitrary STL container, which contains elements of an arbitrary type T. I have a std :: vector which is a copy of all the elements in it. What is the most obvious way to do this?

  template & lt; Typename C & gt; Zero myfunction (C container) {/ * container * / std :: vector & lt; T & gt; Acquire the type of elements within T. Mystack; / * Container and push_back () elements to be converted to MySTAC *  

STL < In the form of code> vector and set , the value_type type should be typed that type the program typed in T .

  std :: vector & lt; Typename c: value_type & gt; Mystack;  

BTW, you do not need to iterate yourself from the container, just use

  template & lt; Typename C & gt; Zero myfunction (const C and container) {std :: vector & lt; Typename c: value_type & gt; Mystack (container.bizin), container.and ()); ...}  

Comments