libstdc++/16612, empty basic_strings can't live in shared memory

Paolo Carlini pcarlini@suse.de
Wed Aug 4 19:25:00 GMT 2004


Hi,

first thank you very much to Nathan and all the posters for your 
constructive
and interesting messages.

>On Wed, Aug 04, 2004 at 09:59:14AM -0700, Nathan Myers wrote:
>  
>
>>  union { _CharT* _M_data; _CharT _M_nul };
>>
>>and define
>>
>>  inline _CharT* c_str()
>>    { return (this->data() ? this->data() : &this->_M_nul); }
>>
>>  inline _CharT& operator[](size_t i)
>>    { return this->c_str()[i]; }
>>
>>One can hope that the optimizer might hoist the test out of loops.
>>(Fat chance.)  
>>    
>>
>This looks good :).  Dirty, but smart.
>  
>
Yes, very smart and would work. However, as Nathan wrote, "let's not be 
hasty":
it's the first time in *years* that someone notices this problem, and I 
still have
hopes there is an even better solution: operator[] is such a *basic* 
operation and
would be *so* sad adding a conditional...

Paolo.



More information about the Libstdc++ mailing list