c++ - Template template support ?
- =?ISO-8859-1?Q?C=E9dric_Paternotte?= (33/33) Aug 03 2007 Hi,
- Walter Bright (3/4) Aug 05 2007 Yes, it does support them, I'll have to look into why this particular
- Cédric Paternotte (17/17) Aug 15 2007 Hi Walter,
Hi, Is DMC not supporting template template arguments ? The following code compiles ok with gcc 4.2 but not with dmc 8.42n. The error is "no match for function test3(...)". About the functions : - test1 takes a vector of ints - test2 takes a vector of objects T - test3 take a container C of objects T Regards, Cédric -------------------- sample code ---------------------- #include <iostream> #include <vector> #include <list> using namespace std; void test1( vector<int>& container ) { cout << "ok" << endl; } template<class T> void test2( vector<T>& container ) { cout << "ok" << endl; } template< template <typename T> class C, class T> void test3( C<T>& container ) { cout << "ok" << endl; } int main() { vector<int> a_vector(5); list<int> a_list(5); test1(a_vector); // dmc ok test2(a_vector); // dmc ok test3(a_vector); // dmc not ok, gcc ok test3(a_list); // dmc not ok, gcc ok return 0; }
Aug 03 2007
Cédric Paternotte wrote:Is DMC not supporting template template arguments ?Yes, it does support them, I'll have to look into why this particular example fails.
Aug 05 2007
Hi Walter, I've been investigating a bit and found a solution. The previous code compiles if test3 is rewritten as : template< class T, class U, template <typename T,typename U> class C> void test3( C<T,U>& container ) { cout << "ok" << endl; } Here the container template "C" has been defined as a 2-parameters template, instead of a 1-parameter template as before. Indeed, STL container templates take 2 parameters : the value type (which is mandatory) and the allocator type (which is optional and comes with a default value). DMC expected the second parameter (the allocator) to be explicitly specified in order to recognize "C" as a valid template template. gcc isn't so rigid in this area but I'm not sure what the standard is saying about this (MS VC++ 2003 behaves like dmc). Chears, Cédric
Aug 15 2007