From 2057722065466630532 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,5f0d50dba412123c,start X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2001-02-14 11:35:03 PST Path: supernews.google.com!sn-xit-02!supernews.com!isdnet!grolier!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail From: Hubert HOLIN Newsgroups: comp.std.c++ Subject: Template function overloading: must every candidate functions be instanciated? Date: Wed, 14 Feb 2001 19:34:33 GMT Organization: =?iso-8859-1?Q?M=E9t=E9o=2DFrance?= Approved: Fergus Henderson , moderator of comp.std.c++ Message-ID: <3A8AB2A5.79CFB902@meteo.fr> Reply-To: Hubert.Holin@Bigfoot.com, Hubert.Holin@meteo.fr X-Trace: mail2news.demon.co.uk 982179282 mail2news:10051 mail2news mail2news.demon.co.uk X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) X-Accept-Language: en,pdf MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 87 Xref: supernews.google.com comp.std.c++:3637 Somewhere in the E.U., le 14/02/2001 Considering the following complete code, my compiler (MetroWerks CodeWarrior Pro 6) indicates a compile error (illegal operand) on line 15, that's the "if (abs(x) <= ::std::numeric_limits::epsilon())" line in the first appearing definition of sinc_pi. The message error in itself is reasonable, as numeric_limits is not instanciated for ::std::complex, and the compiler is trying to instanciate "complex sinc_pi >(const complex x)". However, I wonder if it is necessary to actually instanciate this function. It is necessary to *consider* this function for the overload resolution, but the second function should be preferred as it is more specialized (though the differing return type makes that statement slightly dubious, at least to me), so actually instanciating the first function seems unnecessary. In short, is the following code legal, or not: --- 8>< --------------------------- ><8 --- #include #include #include /* This is the "Sinus Cardinal" of index Pi*/ template inline T sinc_pi(const T x) { using ::std::abs; using ::std::sin; if (abs(x) <= ::std::numeric_limits::epsilon()) { return(T(1)); } else { return(sin(x)/x); } } template class U> inline T sinc_pi(const U x) { using ::std::abs; using ::std::sin; if ((abs(x) <= ::std::numeric_limits::epsilon()) { return(T(1)); } else { return(sin(x)/x); } } /*** ***/ /*** The Problem ***/ /*** ***/ int main() { ::std::complex c(1,2); sinc_pi(c); } --- 8>< --------------------------- ><8 --- Hubert Holin Hubert.Holin@Bigfoot.com Hubert.Holin@meteo.fr --- [ 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 ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.research.att.com/~austern/csc/faq.html ] [ Note that the FAQ URL has changed! Please update your bookmarks. ]