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

前端 未结 2 2060
感动是毒
感动是毒 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:15

    The copy-on-write paradigm is dependent on knowing when you are doing a write. This will occur whenever the object is returning a writable reference.

    If you work with const references to the strings, you may be able to compare the addresses if the class was specialized to disable the copy when returning a const reference to the data.

提交回复
热议问题