Programmatically determine if std::string uses Copy-On-Write (COW) mechanism

前端 未结 2 2059
感动是毒
感动是毒 2021-02-10 21:46

Following up on the discussion from this question, I was wondering how does one using native C++ determine programmatically whether or not the std::string implementation they ar

2条回答
  •  心在旅途
    2021-02-10 22:14

    Using &s1[0] to take the adress is not what you want, [0] returns a writable reference and will create a copy.

    Use data() instead, it returns a const char*, and your tests may pass.

提交回复
热议问题