0

I've seen a few questions asking this from before C++11 started being implemented by compilers. VS2012 currently implements some C++11 functionality, but has plenty of unimplemented C++11 features. I cannot find mention of whether strings are now guaranteed contiguous or not, and am wondering if they are.

The C++11 guarantee of contiguousness is item 21.4.1.5 of this working draft of the standard.

If possible I would like an official citation with the answer.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Peter Clark
  • 2,863
  • 3
  • 23
  • 37
  • 1
    I believe 2010 implements it as well. Unless there is a regression, it should be implemented in 2012. – Jagannath Mar 31 '14 at 00:30
  • Do you happen to have any source for that information? I've edited the question to reflect that I'd like a citation (if possible) with the answer. – Peter Clark Mar 31 '14 at 00:38

2 Answers2

3

Visual C++ has always used contiguous storage for std::string.

One of the design decisions for implementing the contiguity requirement was that all current compilers were doing that anyway. Microsoft is quite well represented on the ISO C++ committee; there's no chance that they overlooked it. Visual C++ did go through a phase of implementing a copy-on-write "optimization" but never was one of the ones using non-contiguous "ropes".

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

I don't know in detail what the standard says, but std::string has the very interesting method c_str() that returns a const char* to the null-terminated string.

I would be crazy to have strings implemented not using contiguous memory. Especially because c_str() is also const.

So, applying the Occam's razor, we can say that it should be safe. And it has nothing to do with C++11, it's applicable also to the older standards.

achedeuzot
  • 4,164
  • 4
  • 41
  • 56
ragazzojp
  • 477
  • 3
  • 14