[RFC] std::string(0);
Dhruv Matani
dhruvbird@gmx.net
Sat Jun 12 03:27:00 GMT 2004
On Sat, 2004-06-12 at 00:13, Martin Sebor wrote:
> Nathan Myers wrote:
>
> > On Fri, Jun 11, 2004 at 07:51:21PM +0200, Daniel Frey wrote:
> >
> >>Martin Sebor wrote:
> >>
> >>>A conforming implementation is not allowed to reject constructs
> >>>such as std::string (0) just because they might cause undefined
> >>>behavior at runtime.
> >>
> >>OK, so this means we can't go the "easy" way. The remaining options are
> >>(AFAICS):
> >>
> >>a) Change the standard, make the above example illegal. Unlikely.
> >>
> >>b) Ask the compiler folks to detected these cases and emit a warning.
> >
> >
> > Reporting this usage at compile time would be a valuable service.
>
> The most frequent complaint I've heard is from users who expect
> it to construct a "null" (i.e., empty) string. AFAIK, that's even
> the behavior on platforms that let you read from address 0. I would
> much prefer defining meaningful behavior for it than turning it
> into an anal retentive error and breaking well-formed programs
> or implementations. Constructing the empty string is IMO perfectly
> reasonable, harmless, and has no adverse performance impact over
> the current behavior (the one if that the requirement is presumably
> trying to eliminate is there anyway in implementations that throw).
Ok, that means that there are 2 definitions of *the empty string*?
1. char* str1 = 0;
2. char* str2 = "\0";
So, according to your definition, both str1 and str2 are empty strings,
having different representations?
Actually, when I started learning about the STL about a year ago, I read
in TC++PL, that end() for a container stood for *one past the last*
valid iterator in a container. So, when I applied it to an empty
container, I was horribly confused!. This meant that an empty container
and a container with only one element should have the same internal
representation!, because end() was one *past* the last, so end() should
be reachable from begin() after incrementing begin() at least once.
However, this is not true for an empty container, because begin() ==
end(). But then after posting, Francis Glassborow helped clear out the
weed, and re-defined end() as the *iterator indicating the end of the
sequence*. So, I'm really scared of double-definitions.
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html
More information about the Libstdc++
mailing list