473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Port to gcc-4.3 (template template issue)

On upgrading from gcc-4.1.2 to gcc-4.3, this (stripped down) code is
now
rejected:

#include <vector>
#include <iostream>

template<typename T, template <typename Aclass CONT=std::vector>
class Ring {

};
template<typename Cont>
inline std::ostream& operator<<(std::ostream& os, const Ring<Cont>& r)
{
os << '[';
os << ']';
return os;
}
g++ -c test1.cc
test1.cc:11: error: type/value mismatch at argument 2 in template
parameter
list for template<class T, template<class Aclass CONTclass Ring
test1.cc:11: error: expected a template of type template<class A>
class
CONT , got template<class _Tp, class _Allocclass std::vector

What is a reasonable way to fix this? The problem is that the 2nd
parameter
says

template<typename Aclass CONT, which doesn't match std::vector
because it
has an optional 2nd parameter (class _Alloc).

I don't want to only match class CONT with those having a 2nd
parameter
(class _Alloc) - that is too restrictive.
Jun 27 '08 #1
2 2353
nd*******@gmail.com wrote:
On upgrading from gcc-4.1.2 to gcc-4.3, this (stripped down) code is
now
rejected:

#include <vector>
#include <iostream>

template<typename T, template <typename Aclass CONT=std::vector>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Invalid code.
g++ -c test1.cc
test1.cc:11: error: type/value mismatch at argument 2 in template
parameter
list for template<class T, template<class Aclass CONTclass Ring
test1.cc:11: error: expected a template of type template<class A>
class
CONT , got template<class _Tp, class _Allocclass std::vector
I am surprised to find out that gcc 4.1.2 allowed that (tested it on mine
with -pedantic -ansi and still allows it, bad gcc).
What is a reasonable way to fix this? The problem is that the 2nd
parameter
says

template<typename Aclass CONT, which doesn't match std::vector
because it
has an optional 2nd parameter (class _Alloc).

I don't want to only match class CONT with those having a 2nd
parameter
(class _Alloc) - that is too restrictive.
The standard clearly specifies that your number and type of template
parameters of a template template parameter must match exactly with the
arguments given (including a default argument). The usual "workaround" is
to properly declare the template template parameter as taking the right
number of template parameters and if you want a default make it so for it,
that is in your case make it:

template<typename T, template <typename A, typename = std::allocator<A
class CONT=std::vector>

C++0x does not remove this restriction (and actually extends it for variable
template parameters too) but I supose C++0x template aliasing feature can
help here (ie you make your code take template template parameter of a
single template parameter but you can create aliases that act like single
parameter templates for std::vector<T, allocator<T and pass that).
--
Dizzy

Jun 27 '08 #2
On May 2, 7:55 am, dizzy <di...@roedu.netwrote:
ndbeck...@gmail.com wrote:
On upgrading from gcc-4.1.2 to gcc-4.3, this (stripped down) code is
now
rejected:
#include <vector>
#include <iostream>
template<typename T, template <typename Aclass CONT=std::vector>

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Invalid code.
g++ -c test1.cc
test1.cc:11: error: type/value mismatch at argument 2 in template
parameter
list for template<class T, template<class Aclass CONTclass Ring
test1.cc:11: error: expected a template of type template<class A>
class
CONT , got template<class _Tp, class _Allocclass std::vector

I am surprised to find out that gcc 4.1.2 allowed that (tested it on mine
with -pedantic -ansi and still allows it, bad gcc).
What is a reasonable way to fix this? The problem is that the 2nd
parameter
says
template<typename Aclass CONT, which doesn't match std::vector
because it
has an optional 2nd parameter (class _Alloc).
I don't want to only match class CONT with those having a 2nd
parameter
(class _Alloc) - that is too restrictive.

The standard clearly specifies that your number and type of template
parameters of a template template parameter must match exactly with the
arguments given (including a default argument). The usual "workaround" is
to properly declare the template template parameter as taking the right
number of template parameters and if you want a default make it so for it,
that is in your case make it:

template<typename T, template <typename A, typename = std::allocator<A
class CONT=std::vector>

C++0x does not remove this restriction (and actually extends it for variable
template parameters too) but I supose C++0x template aliasing feature can
help here (ie you make your code take template template parameter of a
single template parameter but you can create aliases that act like single
parameter templates for std::vector<T, allocator<T and pass that).

--
Dizzy
Thank you so much for the excellent explanation!

It seems to me, though, that this makes template template much less
useful.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vio | last post by:
My story: I played with a little embedded python piece of code (python interpreter embedded in wxWidgets app), and used SWIG to extend this embedded py interpreter. I did it in Linux, after some...
5
by: Jeffrey Barish | last post by:
I have been developing a Python program with two intercommunicating (using sockets) parts, one of which runs on a desktop and the other on a...
1
by: Steve | last post by:
Hello I am working on porting a windows program to linux, unfortunately it doesn't appear the gcc has the ability to understand the following code. ...
9
by: MNQ | last post by:
Hi All I want to use my parallel port of my PC to control some external devices. I am writing a program in ANSI C using the PacificC compiler. What I need to know is how to access the parallel...
66
by: Knady | last post by:
Hi, I have the following problem, I must to do my assignment, but I really do not know how to use the malloc. I need create a program that will be used to do some algebrical computation on the...
4
by: anketm | last post by:
I am writing a simple client using UDP sockets. I am wondering if there is any way to determine what local port a socket was bound to when bind() is not explicitly called. This is what my...
9
by: eeh | last post by:
Hi, I am extremely new to write C programs by GCC. I need to port a C program from GCC(Linux) to GCC(Win32). However, the following errors during compilation: powerSwitch.c `random'...
12
by: david.brown.0 | last post by:
I'm trying to make a Java program access a parallel port. Java's comm API does not provide me with the control I need. I need to be able to write to the data and control pins and read the status...
4
by: H J van Rooyen | last post by:
Hi All, I am writing a polling controller for an RS-485 line that has several addressable devices connected. It is a small access control system. All is well- the code runs for anything from...
2
by: merrittr | last post by:
I have a small program to read data from some data files , in it I use string types to build the data file name but when I try to compile it I get: (see code below error) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.