Solved

Templated template parameters

Posted on 2009-05-07
2
227 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

757 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

20 Experts available now in Live!

Get 1:1 Help Now