This is the mail archive of the egcs@egcs.cygnus.com mailing list for the EGCS project. See the EGCS home page for more information.
On Feb 17, 1999, "Ross Smith" <ross.s@ihug.co.nz> wrote:
> Not true; C++ does support partial specialisation (also called partial
> ordering) of function templates, and it's implemented in EGCS.
That's not partial specialization, it's called overloading with
partial ordering, which is exactly what I implied with the example I
provided. They have different names because they're difference
concepts. If you don't agree, try to get the effect of partial
specialization for the following snippet:
template <typename T> void foo(T);
template <typename T> void foo(T*); // ``specialized'' version
template <typename T> class bar { private: int i;
friend void foo<T>(T);
};
template <typename T> void foo(T) {
bar<T>().i = 0; // ok, I'm a friend
}
template <typename T> void foo(T*) {
bar<T*>().i = 1; // error, I'm not a friend
}
int main() {
int j = 0;
foo(j); // calls foo<int>(int), ok
foo(&j); // calls foo<int>(int*), due to partial ordering, error
foo<int*>(&j); // calls foo<int*>(int*), ok
}
Note that the current release (and the latest snapshot) will fail on
the third invocation too, despite its being perfectly legal :-(
Maybe Mark Mitchell's recently submitted patch for template resolution
in the presence of explicit specifiers will fix this case...
I get:
linux1.markmitchell.com% test-g++ -c test2.C
test2.C: In function `void foo<int>(int *)':
test2.C:15: instantiated from here
test2.C:10: member `i' is a private member of class `bar<int *>'
which looks right to me.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com