473,386 Members | 1,705 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,386 software developers and data experts.

Is this valid ISO C++?

This compiles with MINGW GCC 3.4.2 but not with my other compilers. Is it valid ISO C++?
#include <vector>
template< template<class> class ContainerTemplate, class ValueType>
inline void test(const ValueType &val)
{
ContainerTemplate<ValueType> container(val);
}

int main()
{
using namespace std;

test<vector>(10);
}

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #1
6 1214
"Ioannis Vranos" <iv*@remove.this.grad.com> wrote...
This compiles with MINGW GCC 3.4.2 but not with my other compilers. Is it
valid ISO C++?
#include <vector>
template< template<class> class ContainerTemplate, class ValueType>
inline void test(const ValueType &val)
{
ContainerTemplate<ValueType> container(val);
}

int main()
{
using namespace std;

test<vector>(10);
}


No, this is not valid for a simple reason that std::vector is a template
that has more than one argument. Your 'ContainerTemplate' template
template argument has only one argument itself.

Until we have template typedefs you're probably out of luck. You could
try declaring your own template deriving form 'vector<T>', but you'd
have to duplicate all functionality.

V
Jul 23 '05 #2
Victor Bazarov wrote:
#include <vector>
template< template<class> class ContainerTemplate, class ValueType>
inline void test(const ValueType &val)
{
ContainerTemplate<ValueType> container(val);
}

int main()
{
using namespace std;

test<vector>(10);
}

No, this is not valid for a simple reason that std::vector is a template
that has more than one argument. Your 'ContainerTemplate' template
template argument has only one argument itself.

Until we have template typedefs you're probably out of luck. You could
try declaring your own template deriving form 'vector<T>', but you'd
have to duplicate all functionality.

What I am trying to do is passing a template class (not an instance) to a template
function, and create instances of it inside the function. Something like this:

template <class T>
class SomeContainer{};

template <template<class> class ContainerType>
inline void somefunc()
{
ContainerType<int> obj;
}
int main()
{
somefunc<SomeContainer>();
}

This compiles in all my compilers. What has it do with how many arguments vector takes?

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #3
Ioannis Vranos wrote:

template <template<class> class ContainerType>
inline void somefunc()
{
ContainerType<int> obj;
}
[...]
This compiles in all my compilers. What has it do with how many
arguments vector takes?


The declaration of somefunc says that you'll pass it a template that
takes one argument. vector takes two. To use vector you'd have to
declare somefunc as template<template<class,class> class ContainerType> ...

Except that that doesn't necessarily work, either, because vector can,
hypothetically, take additional implementation-specific arguments.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #4
Ioannis Vranos wrote:

This compiles in all my compilers. What has it do with how many
arguments vector takes?


I looked at the OP and I was wondering the same thing.

vector is defined as: template <class T, class Allocator = allocator>

So, in your function template (to accept vector) you'd have to have
something like:
//---
#include <memory> // for allocator
#include <vector>

template< template<class, class> class CT, class VT, class AT>
inline void test(const VT &val)
{
CT<VT, AT> container(val);
}

int main()
{
using namespace std;

typedef allocator<int> intalloc;
test<vector, int, intalloc>(10);

}
//---

weird stuff (that you can't ignore auto-template parameters)...
--
Peter MacMillan
e-mail/msn: pe***@writeopen.com
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
Jul 23 '05 #5
//---
#include <memory>
#include <vector>

template< template<class, class> class CT, class VT>
inline void test(const VT &val)
{
CT<VT, std::allocator<VT> > container(val);
}

int main()
{
using namespace std;
test<vector, int>(10);
}
//---

Sorry for the extra post. Was just bugged that I didn't need that extra
template parameter. ;0

--
Peter MacMillan
e-mail/msn: pe***@writeopen.com
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
Jul 23 '05 #6
Ioannis Vranos schrieb:
This compiles with MINGW GCC 3.4.2 but not with my other compilers. Is
it valid ISO C++?
#include <vector>
template< template<class> class ContainerTemplate, class ValueType>
inline void test(const ValueType &val)
{
ContainerTemplate<ValueType> container(val);
}

int main()
{
using namespace std;

test<vector>(10);
}


it has been reported earlier as bug to gcc,
see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9737

but it seems they don't want to fix it because it is likely to be valid
in std c++ in the future, DR 150 is mentioned in that context.
Jul 23 '05 #7

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

Similar topics

12
by: lawrence | last post by:
I have a string which I want to send to eval(). How can I test it ahead of time to make sure it is valid code? I don't want to send it to eval and get parse errors. I want to do something like...
16
by: siliconmike | last post by:
Hi, I'm looking for a reliable script that would connect to a host and somehow determine whether an email address is valid. since getmxrr() only gets the mx records.. Links/pointers ? Mike
1
by: Anna | last post by:
Hi all. I have probably a rather stupid question. If there is an HTML document, XML-formed using JTidy, is there any tool to convert it to valid XHTML? I.e. so that all the tags and attribute...
7
by: JR | last post by:
Hey all, I have read part seven of the FAQ and searched for an answer but can not seem to find one. I am trying to do the all too common verify the data type with CIN. The code from the FAQ...
23
by: James Aguilar | last post by:
Someone showed me something today that I didn't understand. This doesn't seem like it should be valid C++. Specifically, I don't understand how the commas are accepted after the function...
3
by: Chris | last post by:
Hi, In C# I tried to save a file from a generated file name. Just before launching the dialog I check for a valid file name to be sure. There for I used the method ValidateNames from the save...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
1
by: Robert Morgan | last post by:
|I'm trying to run a query on a database using php and postgres functions ||<?php db_connect(); $stat = pg_exec($connstr,"SELECT WSID from tblWorkstation "); while ($row = pg_fetch_rows($stat))...
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
10
by: SpreadTooThin | last post by:
Hi I'm writing a python script that creates directories from user input. Sometimes the user inputs characters that aren't valid characters for a file or directory name. Here are the characters...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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...
0
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,...
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...

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.