www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - Template template support ?

↑ ↓ ← =?ISO-8859-1?Q?C=E9dric_Paternotte?= <cpaternotte gmail.com> writes:
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
↑ ↓ 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
↑ ↓ → CÚdric Paternotte <cpaternotte gmail.com> writes:
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