A Surprising Partial Specialization

Discussion in 'C++' started by Michael Olea, Jun 14, 2005.

  1. Michael Olea

    Michael Olea Guest

    I came across code of the following form:

    template<typename T>
    class X { ... };

    template<typename T, size_t N>
    class X<T[N]> { ... };

    I was surprised that the partial specialization has more template parameters
    than does the primary template. I would not have guessed that was possible.
    Now client code of the form:

    template<typename T>
    class Y { ... X<T>::whatever ... };

    .... Y<int[2]> ...

    works as expected (i.e. Y invokes the specialized version of X). Hmm...
     
    Michael Olea, Jun 14, 2005
    #1
    1. Advertising

  2. Michael Olea

    Pete Becker Guest

    Michael Olea wrote:
    > I came across code of the following form:
    >
    > template<typename T>
    > class X { ... };
    >
    > template<typename T, size_t N>
    > class X<T[N]> { ... };
    >
    > I was surprised that the partial specialization has more template parameters
    > than does the primary template. I would not have guessed that was possible.
    > Now client code of the form:
    >
    > template<typename T>
    > class Y { ... X<T>::whatever ... };
    >
    > ... Y<int[2]> ...
    >
    > works as expected (i.e. Y invokes the specialized version of X). Hmm...
    >


    It doesn't have more parameters. The template Y has exactly one
    parameter in both cases. It's just that in the second case you need a
    larger vocabulary to describe that parameter. <g>

    --

    Pete Becker
    Dinkumware, Ltd. (http://www.dinkumware.com)
     
    Pete Becker, Jun 14, 2005
    #2
    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. Chandra Shekhar Kumar

    template partial specialization

    Chandra Shekhar Kumar, Jun 24, 2003, in forum: C++
    Replies:
    17
    Views:
    3,061
    tom_usenet
    Jun 25, 2003
  2. Philip Lawatsch

    Partial Specialization workaround

    Philip Lawatsch, Jul 16, 2003, in forum: C++
    Replies:
    9
    Views:
    413
    Philip Lawatsch
    Jul 16, 2003
  3. Alexander Stippler

    partial specialization of function template

    Alexander Stippler, Aug 15, 2003, in forum: C++
    Replies:
    1
    Views:
    562
    Rob Williscroft
    Aug 15, 2003
  4. Petre Iantu
    Replies:
    1
    Views:
    369
    Petre Iantu
    Aug 17, 2003
  5. Joseph Turian
    Replies:
    2
    Views:
    494
Loading...

Share This Page