Topic: template partial specialzation questions


Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/06/19
Raw View
Terence Kelling wrote:
>
> Is is possible to have a default parameter in a class template and then
> provide a partial specialization for that specific type of class
> template? For example:
>
> template <class T, class U = int>
> class foo {
>
>    // ... stuff
> };
>
> // partial specialization for class U as int
> template <class T>
> class foo<T, int> {
>
>    // ... stuff
> };
>
> void main(void) {
>
>    foo<double, double> f1;    // use the generic template
>    foo<double> f2;            // use the parrtial specialization
>
> };
>
> Also, is this the correct syntax for partially specializing the middle
> parameter of a class template?
>
> template <class T, class U, class V>
> class bar {
>
>    // ... stuff
> };
>
> // partial specialization for class U as int
> template <class T, class V>
> class bar<T, int, V> {
>
>    // ... stuff
> };
>
> I could answer to these questions myself if I had a compiler that could
> handle partial specialization, but I don't.  I'm just going through a
> design process right now.

Both work fine with g++ 2.8.1 - this doesn't proof that it's legal,
but as it is what I'd have expected it's IMHO a strong hint.

For the second example, I'm quite shure it's correct (although I can be
wrong anyway), on the first I'm not so shure (although I don't see
a reason why it shouldn't be).


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Terence Kelling <kelling@arlut.utexas.edu>
Date: 1998/06/02
Raw View
Is is possible to have a default parameter in a class template and then
provide a partial specialization for that specific type of class
template? For example:

template <class T, class U = int>
class foo {

   // ... stuff
};

// partial specialization for class U as int
template <class T>
class foo<T, int> {

   // ... stuff
};


void main(void) {

   foo<double, double> f1;    // use the generic template
   foo<double> f2;            // use the parrtial specialization

};


Also, is this the correct syntax for partially specializing the middle
parameter of a class template?

template <class T, class U, class V>
class bar {

   // ... stuff
};

// partial specialization for class U as int
template <class T, class V>
class bar<T, int, V> {

   // ... stuff
};

I could answer to these questions myself if I had a compiler that could
handle partial specialization, but I don't.  I'm just going through a
design process right now.

Thanks,
Terence Kelling
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]