🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2520

Re: Implicit operation relationships

#2520
From: David Vandevoorde
Date: Sat, 11 Nov 1995 06:03
40 lines
2670 bytes
>>>>> "JB" == John Barton <jjb@watson.ibm.com> writes:
JB> In article <47qnbu$f48@oznet03.ozemail.com.au>, John Max Skaller <maxtal@su
phys.physics.su.oz.au> writes:
JB> |> jjb@watson.ibm.com (John Barton) wrote:
JB> |> >In article <47dn87$a17@sunsystem5.informatik.tu-muenchen.de>,
JB> |> >|> You can extend this idea:
JB> |> >|>
JB> |> >|> template<class T> T  operator- (T&a, T&b) { return a + (-b); }
JB> |> >|> template<class T> T  operator- (T&a)      { return 0 - a; }
JB> |> >|> template<class T> T& operator+ (T&a)      { return a; }
JB> |> >|> template<class T> T& operator++(T&a)      { return a += 1; }
JB> |> >|> template<class T> T& operator++(T&a,int)  { return ++a; }
JB> |> >
JB> |> >This will not work: it prevent you from writing any templates
JB> |> >for these operators over types that do not have "1" or "0"
JB> |> >or that need a definition other than the one above.
JB> |>
JB> |> How does it prevent it? [Quote WP ??]

JB> template<class T>
JB> Matrix<T> operator-(Matrix<T>& rhs) { /* doesn't matter what I code here */
 }

JB> The global operator-(T&) will always win over any more
JB> specific template like the one above.  Unless the standard has
JB> changed here as well.

AFAIK, this has never been true. My understanding is that now the
``most specialized'' (if determinable) specialization will be
selected. Before that, I think you would have an ambiguity.

A template `t<U, V, ...>' would be ``more specialized'' than a template
`t<X, Y, ...>' if there exists some subsitution for `X', `Y', ... that
makes `t<X, Y>' identical to `t<U, V>' but not vice versa.

	Daveed
---
[ 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: <VANDEVOD.95Nov10162731@juicer.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net> <47dn87$a17@sunsystem5.informatik.tu-muenchen.de> <47l76s$qu1@watnews2.watson.ibm.com> <47qnbu$f48@oznet03.ozemail.com.au> <47vjou$i04@watnews2.watson.ibm.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 11 Nov 95 06:03:10 GMT
Approved: fjh@cs.mu.oz.au
From: vandevod@cs.rpi.edu (David Vandevoorde)
Newsgroups: comp.std.c++
Subject: Re: Implicit operation relationships
X-Original-Date: 10 Nov 1995 21:27:31 GMT
Organization: RPI Computer Science
Message-ID: <VANDEVOD.95Nov10162731@juicer.cs.rpi.edu>
References: <MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net>
 <47dn87$a17@sunsystem5.informatik.tu-muenchen.de>
 <47l76s$qu1@watnews2.watson.ibm.com>
 <47qnbu$f48@oznet03.ozemail.com.au>
 <47vjou$i04@watnews2.watson.ibm.com>
In-Reply-To: jjb@watson.ibm.com's message of 10 Nov 1995 19:16:40 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMKQ8reEDnX0m9pzZAQFC/QF+KIaYC8/Dttq/YTDIgc/EjRfT/htxdL2v
 cITQCXU6j2Qok+75MJf61M0rkftyXjui
 =y8mt