Topic: template class in partial specialization


Author: lu <lu_b@my-dejanews.com>
Date: 1999/01/30
Raw View
Hi,
Concerned with portability I have a question regarding partial template class
specialization.
Please, consider a template class:
template <class T1, class T2> class PartialTemplate;
Are the following classes:
template <class T1, class T2> class PartialTemplate<T1,  TemplateClass<T2> >;
and
template <class T1> class PartialTemplate<T1,  TemplateClass<int> >;
different partial specialization of the primary class according to the C++
standard.
Obviously, the last one is a partial specialization but I am wondering if the
second one class is accepted as different specialization by C++ standard.

I have compiled a simple test (the code is given below) using CodeWarrior
release 4, g++2.8, and egcs and all of them give the expected result (below
the code). Is this result expected using any compiler compliant with C++
standard?

Thanks,
Lu

P.S.

template <class T>
class TemplateClass {};

template <class T1, class T2>
class PartialTemplate
{
 public:
    void foo(){cout <<"PartialTemplate<T1,T2>"<<endl;}
};

template <class T1> class PartialTemplate<T1,int>
{
  public:
    void foo(){cout <<"PartialTemplate<T1,int>"<<endl;}
};

template <class T1, class T2>
class PartialTemplate<T1,  TemplateClass<T2> >
{
public:
 void foo(){cout <<"PartialTemplate<T1,TemplateClass<T2> >"<<endl;}
};

template <class T1>
class PartialTemplate<T1,  TemplateClass<int> >
{
public:
 void foo(){cout <<"PartialTemplate<T1,TemplateClass<int> >"<<endl;}
};


int main(void)
{
    PartialTemplate<float,float> pt1;
    PartialTemplate<float,int> pt2;
    PartialTemplate<float, TemplateClass<float> > pt3;
    PartialTemplate<float, TemplateClass<int> > pt4;

    pt1.foo();
    pt2.foo();
    pt3.foo();
    pt4.foo();

    return 0;
}
-----------------------
output
--------
PartialTemplate<T1,T2>
PartialTemplate<T1,int>
PartialTemplate<T1,TemplateClass<T2> >
PartialTemplate<T1,TemplateClass<int> >
------------------

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
---
[ 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              ]