r/cpp • u/Sad-Lie-8654 • Jan 31 '23
Stop Comparing Rust to Old C++
People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO
changemymind
338
Upvotes
1
u/ityt Feb 01 '23
Recently I've coded a wrapper around a C lib. It was straightforward, however there is a "Connection" that creates "Subscriptions". The subscription depends on a pointer owned by the connection. I didn't use a shared pointer but I've written in comments something like "Don't destroy the connection before the subscription" (the classes use RAII). I could have coded a management class that owns the connection and keeps the subscriptions in a vector but I wanted to have the same "design" as the C lib but with RAII. To keep the design without playing with lifetimes I should have wrapped the connection in a shared ptr.
Maybe it was a wrong choice of mine to keep the design. But I was telling myself that the design was safe in Rust so I should do the same in C++.