c++ - C++11 and C++03 differs in support for small string optimization for std::string? -
in compatibility appendix of c++11 standard, 1 of change c++03 c++11 described below:
c.2.11 clause 21: strings library
21.4.1
change: loosen basic_string invalidation rules
rationale: allow small-string optimization.
effect on original feature: valid c++ 2003 code may execute differently in international standard. const member functions, such data , c_str, no longer invalidate iterators.
the iterator invalidation rule of std::string
have changed c++03 c++11 in data()
, c_str()
not allowed invalidate iterators anymore, don't know how leads rationale of "allow small-string optimization
"? wasn't sso allowed prior c++11?
two of differences of std::string
between c++11 , c++03 knew of before came across sso notes in compatibility appendix are:
- elements guaranteed stored contiguously in c++11
- cow implementation not option in c++11 (certain operations such
operator[]
not allowed invalidate iterators)
i took c++11's non-invalidating guarantee of c_str()
, data()
direct result of change towards contiguous storage. seems there connection sso implementation, , know detail of behind-scene logic. thanks.
i believe misinterpreting "change": not referring invalidation rules of data
, c_str
, rather of swap
.
this question gave me idea, , think correct when read quote , linked question/answers.
since basic_string
's swap can invalidate iterators, 1 can implement sso. in c++03, basic_string
reversible container, means had comply requirement swap
ping containers:
the expression a.swap(b), containers , b of standard container type other array, shall exchange values of , b without invoking move, copy, or swap operations on individual container elements.
i may immensely wrong though, ianall (i not language lawyer).
Comments
Post a Comment