Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does C++ supports variable template parameters ?

Reply
Thread Tools

Does C++ supports variable template parameters ?

 
 
Fan Yang
Guest
Posts: n/a
 
      12-07-2006
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.


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      12-07-2006
* 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?
 
Reply With Quote
 
 
 
 
dasjotre
Guest
Posts: n/a
 
      12-07-2006

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.

 
Reply With Quote
 
Fan Yang
Guest
Posts: n/a
 
      12-07-2006
I am sorry, but what's the context?

"Alf P. Steinbach" <(E-Mail Removed)>
??????:(E-Mail Removed)...
>* 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?



 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      12-07-2006

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.

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      12-07-2006
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)
 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      12-07-2006

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.

 
Reply With Quote
 
dasjotre
Guest
Posts: n/a
 
      12-07-2006

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:reprocessor. 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.

 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      12-07-2006
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)
 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      12-07-2006

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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
skipping template parameters inside template parameters kito C++ 2 09-26-2010 12:04 AM
VoIP phone supports IAX2 and SIP,Supports Auto-provision! gery VOIP 1 12-05-2007 07:12 PM
VoIP phone supports IAX2 and SIP,Supports Auto-provision! gery VOIP 0 10-22-2007 03:28 AM
does a "parameters"-parameter overwrite the "parameters"-object? Florian Loitsch Javascript 11 03-15-2005 03:33 PM
implementing policy classes with template template parameters ian C++ 5 10-09-2003 03:19 PM



Advertisments