Topic: Partial Template Specialization


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/09/15
Raw View
In article 95Sep15152129@physics2.Berkeley.EDU, Martin Hitz <hitz@ftp.univie.ac.at> writes:
>
>A while ago, Steve Clamage kindly pointed out to me that partial
>template specializations where allowed by the draft standard.
>
>Thus for a template
>
> template<class T, int n> class X { ... };
>
>it should be possible to explicitly specify a variant for, say,
>
> class X<class T, 1> { ... };
>
>where T is still a "free" formal parameter.
>Although I know that most compiler don't support this feature yet,
>I'am curious about the syntax of such a partial specialization
>(I don't think the above example is correct).

According to the way I read 14.6, class template specialization, [temp.class.spec]
you would write
 template<class T> class X<T, 1> { ... }


---
Steve Clamage, stephen.clamage@eng.sun.com



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: Martin Hitz <hitz@ftp.univie.ac.at>
Date: 1995/09/15
Raw View
A while ago, Steve Clamage kindly pointed out to me that partial
template specializations where allowed by the draft standard.

Thus for a template

 template<class T, int n> class X { ... };

it should be possible to explicitly specify a variant for, say,

 class X<class T, 1> { ... };

where T is still a "free" formal parameter.
Although I know that most compiler don't support this feature yet,
I'am curious about the syntax of such a partial specialization
(I don't think the above example is correct).
Is anybody able to figure that out of the standard document?

Regards,

             Martin Hitz

Applied Computer Science &       |  Email:     Martin.Hitz@univie.ac.at
Information Systems              |  URL:       http://www.pri.univie.ac.at
University of Vienna             |  Phone:     +43-1-40103-2795
Rathausstrasse 19/4              |  Secretary: +43-1-40103-2792
A-1010 Vienna (Austria, Europe)  |  Fax:       +43-1-4066712


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]





Author: self@netcom.com (Gene Linetsky)
Date: 1995/09/23
Raw View
Steve Clamage (clamage@Eng.Sun.COM) wrote:

: In article 95Sep15152129@physics2.Berkeley.EDU, Martin Hitz <hitz@ftp.univie.ac.at> writes:
: >
: >A while ago, Steve Clamage kindly pointed out to me that partial
: >template specializations where allowed by the draft standard.
: >
: >Thus for a template
: >
: > template<class T, int n> class X { ... };
: >
: >it should be possible to explicitly specify a variant for, say,
: >
: > class X<class T, 1> { ... };
: >
: >where T is still a "free" formal parameter.
: >Although I know that most compiler don't support this feature yet,
: >I'am curious about the syntax of such a partial specialization
: >(I don't think the above example is correct).

: According to the way I read 14.6, class template specialization, [temp.class.spec]
: you would write
:  template<class T> class X<T, 1> { ... }


: ---
: Steve Clamage, stephen.clamage@eng.sun.com

One could use it to avoid new and delete in a container:

template <class T, int size> Array
{
 ...
 T array[size];
 ...
}
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]