From: pete@versatilecoding.com   
      
   On 2012-03-30 19:21:36 +0000, Daniel Krügler said:   
      
   > On 2012-03-30 14:21, Pete Becker wrote:   
   >> On 2012-03-30 08:35:57 +0000, Daniel Krügler said:   
   >>   
   >>> On 2012-03-30 05:51, Pete Becker wrote:   
   >>>> On 2012-03-29 21:05:40 +0000, Nikolay Ivchenkov said:   
   >>>>   
   >>>>> On 29 Mar, 23:13, Seungbeom Kim wrote:   
   >>>>>> Therefore, I think an implementation   
   >>>>>> that doesn't keep a null character at the end is making things   
   >> difficult   
   >>>>>> for itself for no good reason I can see.   
   >>>>>   
   >>>>> Such implementations of basic_string are disallowed under C++11 rules   
   >>>>> - see 21.4.7.1/1.   
   >>>>   
   >>>> Not really. c_str() can return a pointer to a newly-allocated array   
   >>>> that holds a copy of the data, with a terminating 0. Sigh.   
   >>>   
   >>> Only in C++03.   
   >>>   
   >>>> But I vaguely recall that there was a change for C++11 that did   
   >>>> disallow this kind of thing, but it's not coming to mind at the moment.   
   >>>   
   >>> This is correct, in C++11 this has changed, both data() and c_str() are   
   >>> now noexcept functions and *both* are required to return a pointer to a   
   >>> null-terminated string.   
   >>   
   >> By themselves, these requirements don't preclude using a shadow buffer.   
   >> Granted, it's perverse, but they can be met by preallocating the shadow   
   >> buffer and resizing it whenever the content of the string is resized.   
   >> I'm not going to dig through the papers now, but I'm pretty sure it was   
   >> Robert Klarer who pointed out that there was a proposed change that   
   >> would require carrying a terminating null in the actual buffer. It might   
   >> have been related to thread support.   
   >   
   > I'm not sure what kind of shadow buffer you mean, but in either case   
   > this buffer would also need to be returned by operator[] of the string,   
   > because we have for c_str()/data:   
   >   
   > "Returns:A pointer p such that p + i == &operator[](i) for each i in   
   > [0,size()].   
   >   
      
   Well, sure. Additional requirements impose additional constraints.   
      
   --   
    Pete   
   Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The   
   Standard C++ Library Extensions: a Tutorial and Reference   
   (www.petebecker.com/tr1book)   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|