Topic: Partial specialization of templates


Author: Xavier Tarrago <Xavier.Tarrago@cea.fr>
Date: 1997/10/29
Raw View
Sorry for two typo errors:

Xavier Tarrago wrote:
>
> template<unsigned int m, unsigned int m> class Matrix {}
                                        ^^
should be:
template<unsigned int m, unsigned int n> class Matrix {}

> template<unsigned int m, unsigned int k, unsigned int m>
                                                        ^^
should be:
template<unsigned int m, unsigned int k, unsigned int n>

  May-be I have not been very clear.
  To summarize,
  Giving a template class & a specialisation of that class:

template <class T1, class T2> class Example{}
template <class T> class Example< T,T> {}

  Giving a template function (NOT a member)

template <class T1, class T2> void my_func( Example<T1,T2>);

  Should the compiler find a template match for the following:

Example<int, int> ei;
my_func( ei); // inst of my_func for specialized template

+--------------------------------------------------------------------------+
| X.Tarrago - mailto:Xavier.Tarrago@cea.fr
|  Commissariat a l'Energie Atomique |
|  Centre de Saclay - bat 611        | tel : 01 69 08 96 49
|  91191 Gif sur Yvette CEDEX        | fax : 01 69 08 75 97
|  France                            |
+------------------------------------+-------------------------------------+
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Xavier Tarrago <Xavier.Tarrago@cea.fr>
Date: 1997/10/28
Raw View
Hello,
  I am looking for help about template partial spec.

  Giving some matrix template class

template<unsigned int m, unsigned int m> class Matrix {}

  Giving some partial specialization for m = n with additionnal
member functions for instance reverse()

template<unsigned int m> class Matrix<m, m> {}

  Now, I try to build a operator*

template<unsigned int m, unsigned int k, unsigned int m>
Matrix<m,n> operator*( Matrix<m,k>, Matrix<k,n>);

  The following statements give an error
Matrix<3,3> p33;
Matrix<3,3> m33;
Matrix<3,3> n33;
p33 = m33 * n33;   // Error with HP aCC

Error 738: "MatrTst.cc", line 92 # Template deduction failed to find a
match for the
    call to 'operator *'.
            p33 = m33 * n33; // Probleme
                  ^^^^^^^^^
*** Error exit code 2

  Should I define an operator* for each pair of spec/unspec templates ?
  I can't find the answer in the Draft.

  Note that the operator is NOT an member. I know that I have to
redefine each
member function for a specialization. (I'd like not to have).

  Thank in advance,
  Xavier Tarrago
--
+--------------------------------------------------------------------------+
| X.Tarrago - mailto:Xavier.Tarrago@cea.fr
|  Commissariat a l'Energie Atomique |
|  Centre de Saclay - bat 611        | tel : 01 69 08 96 49
|  91191 Gif sur Yvette CEDEX        | fax : 01 69 08 75 97
|  France                            |
+------------------------------------+-------------------------------------+
---
[ 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         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]