Does C++ supports variable template parameters ?

Discussion in 'C++' started by Fan Yang, Dec 7, 2006.

  1. Fan Yang

    Fan Yang Guest

    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.
     
    Fan Yang, Dec 7, 2006
    #1
    1. Advertising

  2. * 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?
     
    Alf P. Steinbach, Dec 7, 2006
    #2
    1. Advertising

  3. Fan Yang

    dasjotre Guest

    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.
     
    dasjotre, Dec 7, 2006
    #3
  4. Fan Yang

    Fan Yang Guest

    I am sorry, but what's the context?

    "Alf P. Steinbach" <>
    ??????:...
    >* 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?
     
    Fan Yang, Dec 7, 2006
    #4
  5. Fan Yang

    Noah Roberts Guest

    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.
     
    Noah Roberts, Dec 7, 2006
    #5
  6. Fan Yang

    Pete Becker Guest

    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)
     
    Pete Becker, Dec 7, 2006
    #6
  7. Fan Yang

    Noah Roberts Guest

    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.
     
    Noah Roberts, Dec 7, 2006
    #7
  8. Fan Yang

    dasjotre Guest

    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.
     
    dasjotre, Dec 7, 2006
    #8
  9. Fan Yang

    Pete Becker Guest

    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)
     
    Pete Becker, Dec 7, 2006
    #9
  10. Fan Yang

    Noah Roberts Guest

    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.
     
    Noah Roberts, Dec 7, 2006
    #10
  11. Fan Yang

    kwikius Guest

    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
     
    kwikius, Dec 7, 2006
    #11
  12. Fan Yang

    Noah Roberts Guest

    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
     
    Noah Roberts, Dec 7, 2006
    #12
  13. Fan Yang

    m_pahlevanzadeh

    Joined:
    Jul 8, 2012
    Messages:
    2
    use variadic
     
    m_pahlevanzadeh, Jul 8, 2012
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Leszczynski

    Python supports LSP, does it?

    Andy Leszczynski, Aug 10, 2005, in forum: Python
    Replies:
    13
    Views:
    601
    Guest
    Aug 12, 2005
  2. Steve Kershaw
    Replies:
    1
    Views:
    385
    Teemu Keiski
    May 24, 2007
  3. shailesh

    does CCS supports tail recursion?

    shailesh, Aug 5, 2007, in forum: C Programming
    Replies:
    16
    Views:
    640
    jacob navia
    Aug 6, 2007
  4. kito
    Replies:
    2
    Views:
    444
  5. Florian Loitsch
    Replies:
    11
    Views:
    265
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page