Article View: comp.std.c++
Article #1751Re: STL operators != > <= >=
From: John Max Skaller
Date: Sun, 20 Aug 1995 19:14
Date: Sun, 20 Aug 1995 19:14
67 lines
2984 bytes
2984 bytes
Distribution:
In article <MATT.95Aug16101930@physics2.Berkeley.EDU>,
Joe Buck <jbuck@Synopsys.COM> wrote:
>Distribution:
>maxtal@Physics.usyd.edu.au (John Max Skaller) writes:
>> The STL definitions were in fact quite wrong and
>>completely unnacceptable until overloading of function templates by
>>partial specialisation was introduced into the C++ language.
>>
>> Now the definitions in STL remain wrong, but they are
>>only defaults which can be overriden.
>
>Not true; you can't change the return type (so that, for example,
>< on two arrays of reals returns an array of bools as in APL).
Not true. You CAN. The return type of a
FUNCTION TEMPLATE is part of it's signature. (Unlike ordinary
functions!)
Lets be clear: we're talking about OVERLOADING and
NOT specialisation. You CAN'T specialise a function template
as I understand it.
The "specialisation" rules for functions are rules
of overload resolution. For example:
template<class T, class U> void f(T,U); //#1
template<class T, class U> int f(T,U); //#2
template<class T, class U> int f(U,T); //#3
template<class T> T f(T,T); //#4
f(1,1); // FINE! #4
f<float,int>(1, 1.0); // FINE! #3 is best match
These are distinct templates. The first 3 would always
be ambiguous if used without explicit parameter binding.
template<class T> class APLarray { .. };
template<class T> APLarray<bool>
operator == (APLarray<T> const&, APLarray<T> const&);
template<class T> APLarray<bool>
operator != (APLarray<T> const&, APLarray<T> const&);
is perfectly OK in the presence of the STL globals.
Note the container would NOT be STL compliant.
In fact:
template<class T> T operator != (T const&,T const&);
is perfectly viable too because the return type is different.
(Use would be ambiguous with STL != in reach as well, however)
[BTW: I was surprised at this resolution myself. I'd not have
made the return type part of the signature]
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Aug20111412@Austern>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattReferences:
<3vpmv5$4t7@mujibur.inmind.com> <408o8u$c0p@hermes.synopsys.com> <MATT.95Aug14092229@physics10.berkeley.edu> <MATT.95Aug16101930@physics2.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: maxtal@Physics.usyd.edu.au (John Max Skaller) Newsgroups: comp.std.c++ Subject: Re: STL operators != > <= >= Date: 20 Aug 1995 19:14:11 GMT Organization: School of Physics, University of Sydney, Australia Approved: Matt@Austern Message-ID: <MATT.95Aug20111412@Austern> References: <3vpmv5$4t7@mujibur.inmind.com> <408o8u$c0p@hermes.synopsys.com> <MATT.95Aug14092229@physics10.berkeley.edu> <MATT.95Aug16101930@physics2.Berkeley.EDU> NNTP-Posting-Host: austern.hip.berkeley.edu