Solved

Templated template parameters

Posted on 2009-05-07
2
228 Views
Last Modified: 2012-05-06
It is my understanding that the C++ standard supports templated template parameters, where a template parameter itself is templated.  Recently, I recompiled some old code after upgrading to a higher version of g++.  It was complaining about a templated function where the template parameter was templated.  Since this code had always worked before, and has been working fine for the past couple of years, I was confused why this new version of g++ was having a problem with it.  So, I came up with a very simplified test case, shown below.  This new version of g++ (4.3.2) will not compile the code below, and yet as far as I can see it's perfectly legitimate and works fine when compiled using g++ 4.1.2.

On the other hand, lately newer versions of g++ have only been getting more strict when it comes to the standard, so I wonder if I am misunderstanding the use of templated template parameters, and the code below is in fact not legal for some reason.  

So, my question is, is the code below legal or is this new version of g++ incorrect?  And if g++ is correct about this, how can I fix the code below?
template <template <class> class Array>

void dosomething(const Array<std::string>& array)

{

 

}

 

int main()

{

	std::vector<std::string> vec;

	dosomething(vec);

}

Open in new window

0
Comment
Question by:chsalvia
  • 2
2 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 250 total points
ID: 24324952
>> It is my understanding that the C++ standard supports templated template parameters
Correct


>> So, my question is, is the code below legal or is this new version of g++ incorrect?
The code is incorrect. You MUST match all the template paramters of vector. Since vector takes 2 params (type and allocator) your template template param must match this too.

The code below built fone for me on both VS2008 and g++ 4.2.4
#include <string>

#include <vector>
 

template <template <typename _Ty, typename _Ax> class Array>

void dosomething(const Array<std::string, std::allocator<std::string> >& array)

{

 

}

 

int main()

{

	std::vector<std::string> vec;

	dosomething(vec);

}

 

Open in new window

0
 
LVL 40

Expert Comment

by:evilrix
ID: 24324967
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now