473,763 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<typena me T, template <typename Aclass CONT=std::vecto r>
class Ring {

};
template<typena me 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<typena me 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 2379
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<typena me T, template <typename Aclass CONT=std::vecto r>
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^
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<typena me 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<typena me T, template <typename A, typename = std::allocator< A
class CONT=std::vecto r>

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.ne twrote:
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<typena me T, template <typename Aclass CONT=std::vecto r>

^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^
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<typena me 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<typena me T, template <typename A, typename = std::allocator< A
class CONT=std::vecto r>

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
1600
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 ironing all builds and runs as expected. On a particularily lazy day, I pasted these same wrapper sources to Win32 (cygnus). After fiddling with the Makefile to point in the right directions, compilation seems to go ok (give or take a couple of...
5
2417
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 PDA.  For ease of development, I developed them both on a desktop.  Now that I have them working on the desktop, I need to move the part destined for a PDA to a PDA.  I had originally planned to use a Sharp Zaurus because it runs Linux (the OS of my desktop system) and I had found a Python port that...
1
1466
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. FlushInstructionCache(GetCurrentProcess(),(LPCVOID)Address, Length); VirtualProtectEx(GetCurrentProcess(), (LPVOID)address,Length,PAGE_EXECUTE_READWRITE, &oldperm); WriteProcessMemory(GetCurrentProcess(),(LPVOID)Address, (LPVOID)NewData, Length,
9
8441
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 port ie to send data and to read the state of the parallel port including the control lines. Can anyone help/point me in the correct direction? I have tried the help files and the internet but am unable to find anything relevant. Thanks in...
66
3265
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 matrix. How I can create dynamical the matrices with the name in order to be able to recall them. Thx
4
1825
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 program looks like: sock = socket(PF_INET, SOCK_DGRAM, 0); sendto(sock, message, strlen(message) + 1, 0, (struct sockaddr *) &server, sizeof(server));
9
1777
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' undeclared (first use this function) Besides, I cannot find the online library help of GCC for WIN32? Could anyone give me a web link?
12
8631
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 pins. Any Java people know a good solution? I'm trying to use JNI and create my own library, but building the library gives me these errors: ld: warning: cannot find entry symbol _start; defaulting to 0000000008048094 ParallelPort.o: In...
4
5069
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 three hours to three days, then sometimes when I get a comms error and have to send out a nak character, it fails hard... The traceback below pops up. - the first lines are just some debug prints.
2
2093
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) root@rob-laptop:/home/rob/pankaj# gcc ptcllocate.cpp /tmp/ccg9j6Mi.o: In function `main':ptcllocate.cpp:(.text+0x99): undefined reference to `std::allocator<char>::allocator()' :ptcllocate.cpp:(.text+0xb9): undefined reference to `std::basic_string<char,...
0
9563
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.