Home >Backend Development >C++ >Does C 11 Standard Prohibit Copy-on-Write Implementations for `std::string`?
Legality of Copy-on-Write (COW) Implementation in std::string of C 11
It has been a common belief that Copy-on-write (COW) is not a permissible way to realize a compliant implementation of std::string in C 11. However, recent discussions have challenged this notion.
Does C 11 Prohibit COW Implementations of std::string?
Yes, COW-based implementations of std::string are prohibited in C 11.
Standard Stipulations
The restriction is explicitly stated in the C 11 standard (section 21.4.1 p6):
"Invalidation of iterators/references is only allowed for:
Implication for COW
For a COW string, calling the non-const operator[] would necessitate creating a copy (which would invalidate references). However, this action is prohibited by the standard, rendering COW implementations of std::string non-compliant in C 11.
The above is the detailed content of Does C 11 Standard Prohibit Copy-on-Write Implementations for `std::string`?. For more information, please follow other related articles on the PHP Chinese website!