www.digitalmars.com         C & C++   DMDScript  

c++ - Template template support ?

reply =?ISO-8859-1?Q?C=E9dric_Paternotte?= <cpaternotte gmail.com> writes:

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



-------------------- 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
parent reply Walter Bright <newshound1 digitalmars.com> writes:
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
parent CÚdric Paternotte <cpaternotte gmail.com> writes:
Hi Walter,

I've been investigating a bit and found a solution. The previous code compiles
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

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
this (MS VC++ 2003 behaves like dmc).


Aug 15 2007