?
Solved

Templated template parameters

Posted on 2009-05-07
2
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
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.
Suggested Courses

764 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