#define vs template
Hi guys, in this code I'm using #define s std::set, so I can easily switch to e.g. std::vector or std::list, I was just wondering if there's a way to do this with templates, to make the code a little cleaner and adaptable. Say I want to use the printcont() function for printing an std::set AND an std::vector without having to write the function twice, how would I do that? Without using #define. Please let me know! #include <set> #define s std::set template <typename T> void printcont(s<T> const &a) { typename s<T>::const_iterator itr; for (itr = a.begin(); itr != a.end(); ++itr) std::cout << *itr << "\n"; } template <typename T> void arrpush(s<T>& a, T b[], int size) { for (int i = 0; i < size; ++i) a.insert(b[i]); }