July 23rd, 2012, 9:38 pm
QuoteOriginally posted by: PolterQuoteOriginally posted by: Cuchulainntemplate <typename T, template <typename S,typename Alloc > class Container,typename TAlloc> void print(const Container<T, TAlloc>& container, const std::string& comment){ // A generic print function for sequential containers std::cout << comment << ": "; std::for_each(container.begin(),container.end(), [] (const T& t) { std::cout << t << ", ";}); std::cout << endl;}Why not something like this -- seems simpler and more generic (without needing variadics):template <typename Container>void print(const Container & container, const std::string & comment){ std::cout << comment << ": "; for (const auto & element : container) std::cout << element << ", "; std::cout << std::endl;}I think we're missing the point here. Variadic templates is about a template with an arbitrary number of template parameters. Putting the strategy pattern aside, could it be used for example to specify payoffs in a completely generic and type safe way? Could this Generic payoffs in C++ be implemented with variadics?
Last edited by
ludinski on July 22nd, 2012, 10:00 pm, edited 1 time in total.