Re: basic_string ctor
- From: Tom Widmer <tom_usenet@xxxxxxxxxxx>
- Date: Wed, 18 May 2005 16:22:43 +0100
Duane Hebert wrote:
"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.
What behaviour should we have for passing null? An exception thrown? Certainly I don't particularly like the idea of treating null identically to "", since they aren't the same thing.
Tom .
- Follow-Ups:
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- Re: basic_string ctor
- From: Duane Hebert
- Re: basic_string ctor
- References:
- basic_string ctor
- From: John
- Re: basic_string ctor
- From: Carl Daniel [VC++ MVP]
- Re: basic_string ctor
- From: Duane Hebert
- basic_string ctor
- Prev by Date: Re: sorting in STL
- Next by Date: Re: vector clear
- Previous by thread: Re: basic_string ctor
- Next by thread: Re: basic_string ctor
- Index(es):
Relevant Pages
|