Legality of COW std::string implementation in C++11

后端 未结 7 1472
天涯浪人
天涯浪人 2020-11-22 09:30

It had been my understanding that copy-on-write is not a viable way to implement a conforming std::string in C++11, but when it came up in discussion recently I

7条回答
  •  借酒劲吻你
    2020-11-22 10:05

    From 21.4.2 basic_string constructors and assignment operators [string.cons]

    basic_string(const basic_string& str);

    [...]

    2 Effects: Constructs an object of class basic_string as indicated in Table 64. [...]

    Table 64 helpfully documents that after construction of an object via this (copy) constructor, this->data() has as value:

    points at the first element of an allocated copy of the array whose first element is pointed at by str.data()

    There are similar requirements for other similar constructors.

提交回复
热议问题