Home > Backend Development > C++ > Does C 11 Standard Prohibit Copy-on-Write Implementations for `std::string`?

Does C 11 Standard Prohibit Copy-on-Write Implementations for `std::string`?

Barbara Streisand
Release: 2024-12-19 07:04:14
Original
934 people have browsed it

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:

  • As an argument to any standard library function taking a reference to non-const basic_string as an argument.
  • Calling non-const member functions, except operator[], at, front, back, begin, rbegin, end, and rend.*"

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template