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.


[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]

Re: Template Specialization Again



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...

-- 
Alexandre Oliva  http://www.dcc.unicamp.br/~oliva  aoliva@{acm.org}
oliva@{dcc.unicamp.br,gnu.org,egcs.cygnus.com,samba.org}
Universidade Estadual de Campinas, SP, Brasil