Article View: comp.std.c++
Article #2523Re: Implicit operation relationships
From: Fergus Henderson
Date: Sat, 11 Nov 1995 08:55
Date: Sat, 11 Nov 1995 08:55
36 lines
2116 bytes
2116 bytes
rp@iscp.bellcore.com (Robert Pearlman) writes:
>jjb@watson.ibm.com (John Barton) writes:
>|> schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) writes:
>|> |> template<class T> T& operator+=(T&a, T&b) { return a = a + b; }
>|> |> template<class T> T operator- (T&a, T&b) { return a + (-b); }
>|> |> template<class T> T operator- (T&a) { return 0 - a; }
>|> |> template<class T> T& operator+ (T&a) { return a; }
>|> |> template<class T> T& operator++(T&a) { return a += 1; }
>|> |> template<class T> T& operator++(T&a,int) { return ++a; }
>|>
>|> This will not work: it prevent you from writing any templates
>|> for these operators over types that do not have "1" or "0"
>|> or that need a definition other than the one above.
I don't think that is correct now that partial specialization is
allowed - if you need a different definition, can't you just define a
(template) specialization?
>The substitution for a+=b also won't work; if evaluation of a
>has a side effect the side effect will happen twice.
That's definitely not correct. Templates are not just macro substitution.
The arguments are only evaluated once.
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ 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:
<9531518.10799@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!MattReferences:
<MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net> <47dn87$a17@sunsystem5.informatik.tu-muenchen.de> <47l76s$qu1@watnews2.watson.ibm.com> <47o4oo$6ep@athos.cc.bellcore.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: Implicit operation relationships Date: 11 Nov 1995 08:55:59 GMT Organization: Computer Science, University of Melbourne, Australia Approved: Matt@Austern Message-ID: <9531518.10799@mulga.cs.mu.OZ.AU> References: <MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net> <47dn87$a17@sunsystem5.informatik.tu-muenchen.de> <47l76s$qu1@watnews2.watson.ibm.com> <47o4oo$6ep@athos.cc.bellcore.com> NNTP-Posting-Host: austern.hip.berkeley.edu