This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]