1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-29 20:21:50 +02:00

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

This commit is contained in:
Piotr Idzik
2025-02-09 06:32:46 +01:00
committed by GitHub
parent 932b513d98
commit 8ed47a2e71

View File

@@ -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;
} }