container template??

closed account (SECMoG1T)
Hi am wondering if is possible to write a function that can use any type of
Sequencial container such a vector deque, list n the likes??

1
2
3
4
  /// can do some ting like this if already defined
   funct (vec)/// vec is a vector argument on first call of funct
   funct (lst)/// list is a list arg on second call to funct.
// this is what am wondering.  


Your help will be greatly appreciated.
Last edited on
This is what templates are for:
1
2
3
4
5
6
template<typename Container>
void print_all(const Container& c)
{
    for(auto it = std::begin(c); it != std::end(c); ++it)
        std::cout << *it << ' ';
}
closed account (SECMoG1T)
Well I had no idea of the same because i had multiple errors when defining such a function until I
gave up so i thought templates are only meant for types not containers thanks @minnipaa for the help mean while Am practicing this and see why I got this error.
1
2
3
4
template< typename T>
/// "T is not a template" 

// I got the above error 
It is impossible to tell without rest of the code.

BTW: all functions from <algorithm> are templates: http://en.cppreference.com/w/cpp/algorithm
closed account (SECMoG1T)
Thenk you very much my template function is now working fine on all containers but I have used your way. Thank u n Great insight i dint know how to do it.
Topic archived. No new replies allowed.