Re: basic_string ctor
- From: "Duane Hebert" <spoo@xxxxxxxxxx>
- Date: Tue, 17 May 2005 20:29:56 -0400
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx> wrote in message
news:eUe10xwWFHA.2768@xxxxxxxxxxxxxxxxxxxxxxx
> John wrote:
> > Hi,
> >
> > Is it legal C++ (by which I mean according to the standard spec) to
> > pass a null into a basic_string ctor? Or, more precisely, is it
> > legal C++ to pass a null pointer into a basic_string parameter on a
> > method?
>
> No, it's not. The committee was worried about the cost of the extra if() in
> the constructor being too high (misplaced premature optimization, IMO).
In my opinion the cost of the extra if() would have been well worth
it. One of the problems with the string.h functions was the need to
check everything (if(ptr)(if strlen(prt)) //do something with ptr)
Having functions that take std::string and give expected results
with null would have been great. I've heard from people involved
with the standard that this may be changed.
> Many C++ library implementations will in fact crash if you pass null.
Most that I've used.
.
- Follow-Ups:
- Re: basic_string ctor
- From: Tom Widmer
- Re: basic_string ctor
- From: Stephen Howe
- Re: basic_string ctor
- References:
- basic_string ctor
- From: John
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- basic_string ctor
- Prev by Date: Re: vector clear
- Next by Date: Re: basic_string ctor
- Previous by thread: Re: basic_string ctor
- Next by thread: Re: basic_string ctor
- Index(es):
Relevant Pages
|