Topic: Is this legal? Does it use partial specialization?


Author: Jean-Louis Leroy <100611.1330@compuserve.com>
Date: 1996/12/18
Raw View
Hello,

consider the following code:

struct row_major { };
struct col_major { };

template<class Type, class Layout>
class matrix
 {
 public:
  matrix(const matrix<Type, row_major>& src);
  matrix(const matrix<Type, col_major>& src); // 1
 };

template<class Type, class Layout>
matrix<Type, Layout>::matrix(matrix<Type, row_major>& m) { ... }

template<class Type, class Layout>
matrix<Type, Layout>::matrix(matrix<Type, col_major>& m) { ... }

Someone first told me that this code uses partial specialization, which the
compiler I'm using doesn't support yet; then he told me that it was illegal. I
think he was wrong both times. What do you think? TIA...

Jean-Louis
http://ourworld.compuserve.com/homepages/jl_leroy/
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/12/19
Raw View
Jean-Louis Leroy <100611.1330@compuserve.com> writes:

>struct row_major { };
>struct col_major { };
>
>template<class Type, class Layout>
>class matrix
> {
> public:
>  matrix(const matrix<Type, row_major>& src);
>  matrix(const matrix<Type, col_major>& src); // 1
> };
>
>template<class Type, class Layout>
>matrix<Type, Layout>::matrix(matrix<Type, row_major>& m) { ... }
>
>template<class Type, class Layout>
>matrix<Type, Layout>::matrix(matrix<Type, col_major>& m) { ... }

The code does not use partial specialization.
The code is ill-formed, because you forgot the `const' in the
constructor definitions.  Since there is no instantiation of
the template, then no diagnostic is required, but if
you add e.g.

 matrix<int, row_major> m;

the a diagnostic is required.

If you change the last five lines to

 template<class Type, class Layout>
 matrix<Type, Layout>::matrix(const matrix<Type, row_major>& m) { ... }
 //        ^^^^^

 template<class Type, class Layout>
 matrix<Type, Layout>::matrix(const matrix<Type, col_major>& m) { ... }
 //        ^^^^^

then the code is well-formed.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ 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                             ]