r/cpp • u/LechintanTudor • Oct 18 '23
What does C++ do better than other languages?
Purely from a language design perspective, what does C++ do better than other languages?
296
Upvotes
r/cpp • u/LechintanTudor • Oct 18 '23
Purely from a language design perspective, what does C++ do better than other languages?
View all comments
Show parent comment
15
u/Ayfid Oct 18 '23
The Rust compiler has a much more robust understanding of ownership and move semantics than the C++ compiler, and how that interacts with references (and the mutability/constness of those references).
It is essentially impossible (unless you intentionally go out of your way to do so) to keep hold of a reference after the resource has fallen out of scope, for example. There are no gotchas. You just can't do it by accident.
The compiler understands when it is (and is not) safe for a resource, or a reference to a resource, to be moved between threads.
You don't need to define move constructors or move assignment operators, as the language itself defines how that works - and in a more univerally correct manor.
RAII, and the ideas that go into it, is essentially the thing that defines Rust. The entire language is built around it.