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

Does C++ supports variable template parameters ?

I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b
Many thanks.
Dec 7 '06 #1
11 2516
* Fan Yang:
I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b
Have you heard about "context"? Some statements have context.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Dec 7 '06 #2

Fan Yang wrote:
I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
aka variadic template parameters
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b
I am not aware of any compiler supporting variadic template parameters.

Dec 7 '06 #3
I am sorry, but what's the context?

"Alf P. Steinbach" <al***@start.no>
??????:4t*************@mid.individual.net...
>* Fan Yang:
>I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b

Have you heard about "context"? Some statements have context.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Dec 7 '06 #4

dasjotre wrote:
Fan Yang wrote:
I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."

aka variadic template parameters
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b

I am not aware of any compiler supporting variadic template parameters.
However, in practice this type of template can be created for some
upper number of N. Look at many examples from TR1 and Boost (tuple,
MPL, array, etc...). I'd be surprised if that book doesn't describe
these techneques but I haven't read the whole thing and certainly don't
know it by heart so I can't say what part the OP is talking about.

Dec 7 '06 #5
Noah Roberts wrote:
dasjotre wrote:
>Fan Yang wrote:
>>I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
aka variadic template parameters
>>But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b
I am not aware of any compiler supporting variadic template parameters.

However, in practice this type of template can be created for some
upper number of N. Look at many examples from TR1 and Boost (tuple,
MPL, array, etc...). I'd be surprised if that book doesn't describe
these techneques but I haven't read the whole thing and certainly don't
know it by heart so I can't say what part the OP is talking about.
Yes, you can do it, but it's ghastly. To support 0..N arguments you have
to write N+1 templates. Which is why C++0x will probably have
variable-length argument lists for templates.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 7 '06 #6

Pete Becker wrote:
Noah Roberts wrote:
However, in practice this type of template can be created for some
upper number of N. Look at many examples from TR1 and Boost (tuple,
MPL, array, etc...). I'd be surprised if that book doesn't describe
these techneques but I haven't read the whole thing and certainly don't
know it by heart so I can't say what part the OP is talking about.

Yes, you can do it, but it's ghastly. To support 0..N arguments you have
to write N+1 templates. Which is why C++0x will probably have
variable-length argument lists for templates.
>From what I've seen it's more like N/X with X default parameters. For
instance, mpl's vector is implemented in terms of a vector10, vector20,
vector30...which have 10, 20, and 30 default parameters.

Dec 7 '06 #7

Noah Roberts wrote:
dasjotre wrote:
Fan Yang wrote:
I'm reading Modern C++ Design, and it is saying "Variable template
parameters simply don't exist."
aka variadic template parameters
But I find VC7.1 & VC8 support this feature.Who can tell me that which is
right -_-b
I am not aware of any compiler supporting variadic template parameters.

However, in practice this type of template can be created for some
upper number of N. Look at many examples from TR1 and Boost (tuple,
MPL, array, etc...). I'd be surprised if that book doesn't describe
these techneques but I haven't read the whole thing and certainly don't
know it by heart so I can't say what part the OP is talking about.
In 'Modern C++ Design', he uses that technique to design type lists
and function wrappers. It is tedious and best done with something like
m4 or boost::preprocessor. Than again, having type lists, I see no
reason why you couldn't use them to emulate variadic template
parameters, up to the maximum length of the type lists.

But that is not a true variadic template like the ones you have in D.

Dec 7 '06 #8
Noah Roberts wrote:
Pete Becker wrote:
>Noah Roberts wrote:
>>However, in practice this type of template can be created for some
upper number of N. Look at many examples from TR1 and Boost (tuple,
MPL, array, etc...). I'd be surprised if that book doesn't describe
these techneques but I haven't read the whole thing and certainly don't
know it by heart so I can't say what part the OP is talking about.
Yes, you can do it, but it's ghastly. To support 0..N arguments you have
to write N+1 templates. Which is why C++0x will probably have
variable-length argument lists for templates.
>>From what I've seen it's more like N/X with X default parameters. For
instance, mpl's vector is implemented in terms of a vector10, vector20,
vector30...which have 10, 20, and 30 default parameters.
I haven't looked at the details there, but from a glance it seems like
that's just part of a divide and conquer approach for the preprocessor,
where each of those templates in turn generates 10 template classes.

Sooner or later you have to decide which template arguments are real and
which ones aren't.

Of course, any program that needs to pass more than ten template
arguments is out of control. <g>

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 7 '06 #9

Pete Becker wrote:
I haven't looked at the details there, but from a glance it seems like
that's just part of a divide and conquer approach for the preprocessor,
where each of those templates in turn generates 10 template classes.
Possible, but it would be surprising. Compiler output from errors
indicate the final types contain the default values; at least when
using MPL vector. But I haven't done a lot of looking either.
>
Sooner or later you have to decide which template arguments are real and
which ones aren't.

Of course, any program that needs to pass more than ten template
arguments is out of control. <g>
Well, the basic dimensional analysis idiom requires something like 8 or
9 so more than 10 isn't really outside reason in metaprogramming.

Dec 7 '06 #10

Pete Becker wrote:
Of course, any program that needs to pass more than ten template
arguments is out of control. <g>
My compiler goes to 11...

(Just For the Spinal Tap fans ;-) )

regards
Andy Little

Dec 7 '06 #11

kwikius wrote:
Pete Becker wrote:
Of course, any program that needs to pass more than ten template
arguments is out of control. <g>

My compiler goes to 11...

(Just For the Spinal Tap fans ;-) )
What's funny is my amp DOES go to 11 :P

Dec 7 '06 #12

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

Similar topics

3
by: Karsten Weinert | last post by:
Hi! Can you please explain to me the difference between a xsl:param and a xsl:variable? Since I can assign a value to both only once, what's the point? A small example would help me a lot. ...
11
by: Saqib Ali | last post by:
Please excuse me, this is a fairly involved question that will likely require you to save the file below to a file and open it in a browser. I use Mozilla 1.5, so the problem I describe below...
3
by: martin.druon | last post by:
Hi, I created a template class to represent hypermatrix. I would like to add methods where the number of parameters are checked during the compilation time. For example : template <size_t...
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...
3
by: John Shell | last post by:
Hello, all. The following code results in a C2666 error (2 overloads have similar conversions). class FSVec2D { public: FSVec2D() { // code omitted }
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
0
by: Orin | last post by:
Hi, Here is my task: - need to get text from a template variable. For example we have a text with templates "Cars" and "Producers": "{{Cars|Toyota=blablabla |Moskvitch=blablabla...
2
by: Pierre Yves | last post by:
Hi there, Sorry for the double subject but I feel they are related. I'm not pretty sure there would be an answer but I reckon there must be a way to make it work. I would like to write the...
32
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...

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.