(ref.doc)maxtal 150395

Next clamage 130395 Prev: ark 140395 Up: Usenet

Newsgroups: comp.std.c++     (Note:
 maxtal.)
Subject: Re: Partial specializations? (Was: Sealed Classes)
Date: Wed, 15 Mar 1995 21:33:35 GMT

>John, could you, or someone else in the know, let the rest of us know
>more or less what "partial specializations" are?

	Sure. Even better, I've been told that they _have_ been accepted
at least in some form. First, consider a class template:

	template<class T, class U> class X { .. };

As you know you can write a specialisation:

	class X<int, int> { ... };

But what if you only want to specialise the first argument?
Can you write:

	template<class U> class X<int, U> { .. };

?? Well, the answer is: two weeks ago you could not, but 
I believe now you can. Here's another example:

	template<class T> class X<T*, T***> { ... }

The resolution of which definition to use is done by
asking which of the "generic bindings" which might
apply to a particular instance is most specific (i.e. most
specialised). For example:

	<T*, T***> is more special than <A, B**>

Thats classes. Now consider the problem:

	template<class T> void f(T);
	template<class P> void f(P*);
	int i;
	f(&i); // Ambiguous??

Both templates can generate a definition of 

	f(int*)

Which one should be used? Two weeks ago, this was ambiguous,
now the answer is "the second template, because it is
more specialised".

You will note "specialisations" form a DAG. Do not be
surprised at the analogy with (multiple) inheritance: virtual
function overriding is exactly the same kind of specialisation
as template specialisations. (The principal difference is
the binding time)
-----------------------------------------------------------------

I'm not aware of the exact rules. I'm sure there will be some
interesting problems, however. But one thing is for sure:
templates without partial specialisations would fail completely
to be orthogonal enough to construct significant libraries.

In particular, partial specialisations are necessary to make STL
maximally useful.

automatically generated by info2www version 1.2.2.8