Legality of Copy-on-Write (COW) std::string Implementation in C 11
Although it may have been believed that COW is not a feasible technique for implementing a compliant std::string in C 11, recent discussions have raised uncertainties. The following explores the validity of this assumption based on the new standard.
Prohibition of COW-Based std::string Implementations in C 11
C 11 explicitly prohibits COW-based implementations of std::string. This limitation is stated in section 21.4.1 p6 of the standard, which permits invalidation of iterators/references only in specific circumstances:
In a COW string, invoking non-const operator[] necessitates creating a copy (invalidating references), which is forbidden by the aforementioned paragraph. Consequently, COW strings are prohibited in C 11 due to this constraint.
The above is the detailed content of Is a Copy-on-Write std::string Implementation Legal in C 11?. For more information, please follow other related articles on the PHP Chinese website!