Topic: problem with string::resize


Author: alfps@start.no ("Alf P. Steinbach")
Date: Mon, 13 Feb 2006 17:00:19 GMT
Raw View
[for comp.std.c++: this started out regarding 'resize', and developed
into discussing 'reserve']

* Daniel T.:
> * Duane Hebert:
> > * Alf P. Steinbach:
 > > >
> > > The [reserve] request is non-binding for /reducing/ the capacity.
> > > It is binding for /increasing/ the capacity.  After a call to
 > > > reserve() a call to capacity() must be equal or greater,
> > > and capacity() is "the size of the allocated storage in the
 > > > string".
 > >
> > As far as string not being contiguous, is this still true?
> >
> > Even so, does anyone know of an implementation where it isn't?
>
> What about strings that use a reference counted implementation, and then
> there is SGI's "rope" class. I personally have a string class that uses
> a deque as its representation (the interface is still incomplete though.)

A reasonable interpretation of the standard's text, quoted above, is
that if s has capacity n then assignment of a string of n characters to
s will not fail  --  it would have been nice if that was stated
explicitly, but then the standard isn't even clear on what a region of
storage is (at least one committee member thinks it means any number of
scattered small regions), presumably to provide leeway for compilers.

I.e. the natural interpretation, as I see it, is that the storage
referred to is not the storage in some way owned by the string instance,
for that would be meaningless, but is the storage guaranteed to be
available for storing characters, for this instance.

How that is accomplished only affects the operational efficiency in
various contexts, not what can be assumed about success of operations.


I've taken the liberty of multi-posting this to [comp.std.c++], that is,
a separate posting of the same message to that group.  I hope.  If
Thunderbird does what I think it will do.

I.e., language lawyer level discussion in csc++, slow mode, and
practical aspects (if any remain to be discussed) in clc++, fast mode.


[Grumble: Thunderbird messes up editing of quoted text with invisible
modes, refusing to do what I want, and inserting spaces in the final
result, invisible while editing.  Has some Outlook Express programmer
infiltrated the Mozilla team?  Otherwise excellent Thunderbird...
Anyway, if the quoted text is messed up, that's why.  Looks fine here.]

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]