Article View: comp.std.c++
Article #1917Re: operator[]: Should I follow the conventional style?!
From: Alex Martelli
Date: Wed, 06 Sep 1995 18:06
Date: Wed, 06 Sep 1995 18:06
59 lines
2414 bytes
2414 bytes
kanze@gabi-soft.fr (J. Kanze) writes (in comp.lang.c++):
>Wil Evers (wil@ittpub.nl) wrote:
...
>|> array[index].doSomethingToIt(args);
...
>|> Please note that at least some compilers - I'm not sure if this is
>|> standard-conforming - will accept the second syntax even when we're using
>|> the proxy approach. They will call doSomethingToIt() on the temporary
>|> returned by the array's get() member function and then discard it. In
>|> other words, the array element at index is not changed at all!
in the context of something like (I'm synthesizing from word-level
descriptions by Kanze and Evers):
class A {
...
public:
int doSomethingToIt(int args);
};
class proxyA;
class arrayA {
...
public;
A& get(int index);
void put(int index, const A&it);
proxyA operator[](int index);
};
class proxyA {
arrayA& thearray;
int theindex;
public:
proxyA(arrayA& inar, int inin): thearray(inar), theindex(inin) {}
operator A() { return thearray.get(theindex); }
void operator=(const A& it) { thearray.put(theindex, it); }
};
In this case, the behaviour Wil describes is not standard conforming,
I believe; conversions are NOT supposed to be applied to the implicit
"this" operator of any member function, here doSomethingToIt()!
YesNo...?
Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia Fax: +39 (51) 597120
---
[ 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.95Sep6110625@physics2.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<KANZE.95Aug23140518@slsvhdt.lts.sel.alcatel.de> <1995Aug25.112209.1490@ittpub> <41klg4$235@gabi.gabi-soft.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: martelli@cadlab.cadlab.it (Alex Martelli) Newsgroups: comp.std.c++ Subject: Re: operator[]: Should I follow the conventional style?! Date: 06 Sep 1995 18:06:25 GMT Organization: Cad.Lab Spa, Bologna, Italia Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <MATT.95Sep6110625@physics2.Berkeley.EDU> References: <KANZE.95Aug23140518@slsvhdt.lts.sel.alcatel.de> <1995Aug25.112209.1490@ittpub> <41klg4$235@gabi.gabi-soft.fr> NNTP-Posting-Host: physics2.berkeley.edu