Re: [Stlport-devel] string, operator [] const
Brought to you by:
complement
From: <fra...@fr...> - 2006-01-26 20:20:26
|
Don't worry, c_str never reallocate internal buffer. Even if null=20 terminated character is not always appended to the internal string=20 buffer there is always enough place for it. Bests Petr Ovtchenkov wrote: > Fran=E7ois, > > The modification > > + //First implementation use c_str in order to guaranty return of a nu= ll > + //character when __n =3D=3D size() > const_reference operator[](size_type __n) const > -#if defined (_STLP_FORCE_STRING_TERMINATION) > - { return *(this->_M_Start() + __n); } > -#else > - { return __n =3D=3D size() ? __STATIC_CAST(const _CharT&, _STLP_DEFA= ULT_CONSTRUCTED(_CharT)) : *(this->_M_Start() + __n); } > -#endif > + { return this->c_str()[__n]; } > > is wrong, IMHO --- it may lead, for example, to unexpected reallocation= in the const string: > > const string s( "1234...." ); > > const char *data1 =3D s.data(); > > s[s.size()]; > > const char *data2 =3D s.data(); > > Now data1 may be not equal data2, without explicit modification! > > Bests, > > - Petr > > > P.S. I will be far enough from computers ~1 week, so will answer later. > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log = files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D103432&bid=3D230486&dat= =3D121642 > _______________________________________________ > Stlport-devel mailing list > Stl...@li... > https://lists.sourceforge.net/lists/listinfo/stlport-devel > > > =20 |