Topic: basic_string& operator=(const basic_string&
Author: penewson@novice.uwaterloo.ca (Paul Newson)
Date: 1996/02/06 Raw View
>The following was taken from a copy of the DWP:
>
> basic_string<charT,traits,Allocator>&
> operator=(const basic_string<charT,traits,Allocator>& str);
>
> Effects:
> If *this and str are not the same object, modifies *this such that:
>
> Table 7--operator=(str) effects
>
> +-------------------------------------------------+
> | Element Value |
> +-------------------------------------------------+
> |data() points at the first element of an |
> | allocated copy of the the array |
> | whose first element is pointed at |
> | by str.size() |
> |size() str.size() |
> |capacity() a value at least as large as size() |
> +-------------------------------------------------+
> If *this and str are the same object, the member has no effect.
> Returns:
> *this
>
>Aside from a seeming typographical error in the Value column for Element data()
>(... by str.data() ?) the wording of this seems to rule out a counted pointer
>representation.
>
>Is my interpretation correct?
>
>--
>John Hickin Bell-Northern Research, Montreal, Quebec
>(514) 765-7924 hickin@bnr.ca
>---
Because str.data() is a member function, a counted pointer implementation of
the string class could perform a copy on write at the time of the call to
str.data(). Member functions to return constant iterators, for example, need
not cause the string to be copied, so a counted pointer implementation of
the string class could still be written. (At least, the definition of
str.data() does not rule it out, there might be something else that does.)
Paul Newson
penewson@novice.uwaterloo.ca
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Author: clamage@taumet.eng.sun.com (Steve Clamage)
Date: 1996/02/07 Raw View
My original posting was somewhat ill-posed. What I really meant to say
was that it seems to me that a counted pointer representation is to ruled
out in practice because the DWP wording, in my opinion, prevents the
representation to be shared in the only case that makes sense to share.
I interpret the phrase
points at the first element of an
allocated copy of the the array
whose first element is pointed at
by str.data()
^^^^<--------- my 'wording' now
as meaning that if we had a string x without sharers then string y(x)
would necessarily create another string without sharers.
--
John Hickin Nortel Technology, Montreal, Quebec
(514) 765-7924 hickin@bnr.ca
[ 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://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Author: "john (j.d.) hickin" <hickin@bnr.ca>
Date: 1996/02/08 Raw View
My original posting was not terribly explicit. My interpretation of the
wording in Table 7 is that an assignment x=y cannot share the string data
of y. My interpretation of Table 3 for the copy constructor is the same:
string x(y) cannot sahre y's data. I conclude, therefore, that a counted
pointer representation is allowed in theory but 'prevented in practice'.
--
John Hickin Nortel Technology, Montreal, Quebec
(514) 765-7924 hickin@bnr.ca
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. Moderation policy:
http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]