Make the code example `c++20` compliant (#8177)

pull/8185/head
Piotr Idzik 3 months ago committed by GitHub
parent 932b513d98
commit 8ed47a2e71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      src/data/roadmaps/cpp/content/112-idioms/106-copy-write.md

@ -20,7 +20,7 @@ public:
// Make a copy only if we want to modify the data. // Make a copy only if we want to modify the data.
void write(const std::string &str) { void write(const std::string &str) {
// Check if there's more than one reference. // Check if there's more than one reference.
if(!data.unique()) { if(data.use_count() > 1) {
data = std::make_shared<std::string>(*data); data = std::make_shared<std::string>(*data);
std::cout << "Copy is actually made for writing." << std::endl; std::cout << "Copy is actually made for writing." << std::endl;
} }

Loading…
Cancel
Save