From 5550333285834956531
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,cc1a555bbe9617a3
X-Google-Attributes: gidf78e5,public
From: Matt Austern <austern@sgi.com>
Subject: Re: STL and SGI and strings
Date: 1998/01/13
Message-ID: <fxten2cnv4y.fsf@isolde.mti.sgi.com>#1/1
X-Deja-AN: 315647366
References: <34B57837.41C6@pixar.com> <34B6580F.6A50@pratique.fr> <69e5d5$eki$1@news2.ispnews.com>
X-Original-Date: 13 Jan 1998 09:25:49 -0800
Originator: austern@isolde.mti.sgi.com
Organization: SGI
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNLvX1Uy4NqrwXLNJAQHsEAH+IUjrDQV2wO1hMUBhwrBb9Rm4Kzgl2Dx8 KkBimgXCJgXXhfTgztVghACBoe83PGsNy06sNpg30LX2WendtFFGMQ== =oTPT
Newsgroups: comp.std.c++


"Brock" <peabody@npcinternational.com> writes:

> >The problem is that sharing is often impossible as:
> >- operator[] has to return a charT&
> 
> 
> Does it have to return a charT& according to the standard?  I read somewhere
> (More Effective C++?) about an efficient way to determine whether operator[]
> was used for read or write access by returning an object with an overloaded
> operator=(charT), and an operator charT().  I even wrote a (hopeless) email
> to my vendor (MS) complaining that their std::string implementation didn't
> use this technique, as I had assumed it to be the standard way to do it.

Yes, the standard does require that that basic_string<>::operator[]
return a charT&.  Proxy references are not allowed.

Changing from charT& to a proxy reference class is not an
implementation detail, but a visible change in the interface.  To take 
one trivial example: at present, if s is a string, the expression 
std::swap(s[0], s[1]) is legal.  If operator[] returned a proxy
reference, though, it would not be.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



