Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Templated template parameters

Posted on 2009-05-07
2
Medium Priority
?
235 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

610 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