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

question on template template parameters

REH
GCC accepts this in a template parameter list:

template<class> class T = std::vector

However Visual C++ conplains because the actual template parameter list of
std::vector does not match, because of course the defaulted allocator
parameter. So, technically its correct. But what does the standard say?
Does it allow the above? Stroustrup's "The C++ Programming Language" (SE)
uses the above in several examples.

Thanks,

REH
Jul 23 '05 #1
3 1167
REH wrote:
GCC accepts this in a template parameter list:

template<class> class T = std::vector

However Visual C++ conplains because the actual template parameter list of
std::vector does not match, because of course the defaulted allocator
parameter. So, technically its correct. But what does the standard say?
Does it allow the above? Stroustrup's "The C++ Programming Language" (SE)
uses the above in several examples.


The acceptance of this depends on the implementation of 'std::vector'.
It is possible that the implementation has only one argument for that
template. In that case the code is valid. It is also possible that
the implementation has several arguments, in which case the program that
_assumes_ only one argument is ill-formed.

Until "template typedefs" are introduced into the language, you could
work around the error by wrapping the 'std::vector' into another template:

template<class T> struct vector_def_alloc {
typedef std::vector<T> type; // the allocator used is the default
};

.... template<class> class T = vector_def_alloc::type ...

(or something like that)

V
Jul 23 '05 #2
REH

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:1o***********@newsread1.mlpsca01.us.to.verio. net...
The acceptance of this depends on the implementation of 'std::vector'.
It is possible that the implementation has only one argument for that
template. In that case the code is valid. It is also possible that
the implementation has several arguments, in which case the program that
_assumes_ only one argument is ill-formed.

Until "template typedefs" are introduced into the language, you could
work around the error by wrapping the 'std::vector' into another template:

template<class T> struct vector_def_alloc {
typedef std::vector<T> type; // the allocator used is the default
};

... template<class> class T = vector_def_alloc::type ...

(or something like that)

V


Thanks Victor. Is there a better way of doing this type of thing than
template template parameters? Basically, I want to be able to instantiate
the class template with different types of containers, but I want a policy
that enforces that the container's element type is a specific type. In
other words, the container type is definable, but the element type is not.

REH
Jul 23 '05 #3
REH wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:1o***********@newsread1.mlpsca01.us.to.verio. net...
The acceptance of this depends on the implementation of 'std::vector'.
It is possible that the implementation has only one argument for that
template. In that case the code is valid. It is also possible that
the implementation has several arguments, in which case the program that
_assumes_ only one argument is ill-formed.

Until "template typedefs" are introduced into the language, you could
work around the error by wrapping the 'std::vector' into another template:

template<class T> struct vector_def_alloc {
typedef std::vector<T> type; // the allocator used is the default
};

... template<class> class T = vector_def_alloc::type ...

(or something like that)

V

Thanks Victor. Is there a better way of doing this type of thing than
template template parameters? Basically, I want to be able to instantiate
the class template with different types of containers, but I want a policy
that enforces that the container's element type is a specific type. In
other words, the container type is definable, but the element type is not.


Did you mention "Policy"?... Somebody mentioned "policy", anyway... I
definitely heard something that sounded like "policy"...

If you're up to it, take a look at "Modern C++ Design". It's all about
policies and how you use them.

V
Jul 23 '05 #4

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

Similar topics

2
by: CoolPint | last post by:
Can anyone kindly explain why non-type template parameters are required by giving some examples where their uses are clearly favourable to other alternatives? I cannot think of any good use for...
0
by: Mikael Petterson | last post by:
Hi, I am trying to produce the following in javacode; public void action<An actionName>(String value1, int value 2....,Coordinator c) throws Exception; The arguments to the actionXXX could...
1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
7
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions...
6
by: rincewind | last post by:
Hi, can anybody summarise all options for partial template specialization, for all kind of parameters (type, nontype, template)? I *think* I understand options for partial specialization on...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
8
by: Paul Roberts | last post by:
Hi, I'm hoping somebody here can help me with a simple problem of template syntax. Here's an example: template<typename T, int iclass A { static int a;
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
3
by: nooneinparticular314159 | last post by:
I'm trying to do a template with specialization. I declare two templates, one of which looks like: template<int a, int b> struct MOO { enum{ VALUE = b == 0 ? a: MOO<some stuff>::VALUE };
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.