From 6689203760242465871
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,b83a4267f4ac775
X-Google-Attributes: gidf78e5,public
From: Valentin Bonnard <bonnardv@pratique.fr>
Subject: Re: string/cow/algorithm
Date: 1998/08/11
Message-ID: <35D0B753.1C9D@pratique.fr>#1/1
X-Deja-AN: 380207557
X-NNTP-Posting-Host: cyber93-9.paris.imaginet.fr
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <6qfr41$oue$1@pigpen.csrlink.net> <6qg3ld$r7o$1@shell7.ba.best.com> <6qgs0r$92e$1@pigpen.csrlink.net> <35ccc2b4.832003@news3.ibm.net> <6qn19u$sb0$1@pigpen.csrlink.net> <6qnj99$h2l$1@nnrp1.dejanews.com> <6qo3fq$dum$1@pigpen.csrlink.net>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset=us-ascii
Organization: Ecole Normale Superieure, Paris, France
Mime-Version: 1.0
Reply-To: bonnardv@pratique.fr
Newsgroups: comp.std.c++
Originator: clamage@taumet


John Potter wrote:
> 
> The original question was the conformance of a string class which
> sorted the original string when a copy was sorted.  The answer was
> that the FDIS is different from the CD2 and the implementation is not
> conformant.  A following question asked about making a cow string
> class conformant.
> 
> On writing a standard conformant string class.
> 
> AllanW@my-dejanews.com wrote:
> 
> : I think that using a proxy class should handle this fairly well

Not really

> Sorry.  Unless this has also changed from the CD2, it is required that
> string::operator[] return a T& and that string::iterator::operator*
> return a T&.  Proxies are expressly forbidden by these requirements.

You are perfectly right.

> However, I am interested in any standard
> conformant techniques that may help Mark do a better job than the
> little relayed information which I posted.  Or maybe there are no
> better techniques.

The user can get a reference or pointer to the one 
charT in a basic_string. You have *no way* to remplace 
these with UDT, change their behaviour or be told when 
they go out of scope. So once you have released them, 
you are unsharable as long as they are valid.

If iterator is charT*, then begin() and end() put 
you in the unsharable state. If iterator is a UDT, 
then you have to mark the string as unsharable when 
the iterator is dereferenced (or before).

Few programmers call begin() or end() just for fun; 
most will dereference the iterator at some point, 
generally just after. So what's the point ?

The point is that there will be an unsharable state 
in a cow basic_string. The question is how many strings
are in this state, and is there still a significant 
gain, or a gain at all (it's application dependant, of 
course).

Using const std::string& as arguments is still a good 
idea. The compiler can optimise std::string return values. 
There are still cases where you copy a string without 
touch-ing it.

-- 

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




