Why should it?still modify the first character of the string??
buf won't change automatically when _M_p changes.
If you have
b doesn't become 10. Same thing there.Code:int a = 5; int b = a; a = 10;
And how would you update _M_length?
And even if you can make it work, this is only for this particular version of GCC. Another implementation or even another version of GCC can do it totally differently.
If you are so concerned about performance that you can't afford the copying, it would be much easier to roll your own string class. Much safer, too.