From 1845101929264574318
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,cc1a555bbe9617a3
X-Google-Attributes: gidf78e5,public
From: Valentin Bonnard <bonnardv@pratique.fr>
Subject: Re: STL and SGI and strings
Date: 1998/01/13
Message-ID: <34BB95E3.41C67EA6@pratique.fr>#1/1
X-Deja-AN: 315647363
References: <34B57837.41C6@pixar.com> <34B6580F.6A50@pratique.fr> <69e5d5$eki$1@news2.ispnews.com>
X-Original-Date: Tue, 13 Jan 1998 17:27:15 +0100
Originator: austern@isolde.mti.sgi.com
Organization: Ecole Normale Superieure, Paris, France
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNLvXiEy4NqrwXLNJAQHFMgH/R/v+MASvn5VxaEMFJ7Qa2Bj6dhppqFv0 pmdhVrPqgHL2nHDP4o1HOi6uvbDAuZ0EcZ8UzuZC7GaHj3fQtcHyCA== =MF+U
Newsgroups: comp.std.c++


Brock wrote:
> 
> Valentin Bonnard wrote in message <34B6580F.6A50@pratique.fr>...
> <<<
> 
> >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.
> 
> <<<

>From 23.1.1  Sequences, Table 6:

a[n]            T&; const T&     *(a.begin() + n)
                for constant a

string is a sequence; also from 21.2  String classes/4:

          const_reference operator[](size_type pos) const;
          reference       operator[](size_type pos);
          const_reference at(size_type n) const;
          reference       at(size_type n);

The standard can't be clearer. Don't complain when your 
implementor (especially MS) is right, it's so rare.

You can implement your classes the way you want, BTW.

-- 

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://www.pratique.fr/~bonnardv/
---
[ 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 
]



