Skip to content

Comment on Too dangerous for C++

Comments

See also:

https://www.boost.org/doc/libs/1_65_0/libs/smart_ptr/doc/htm...

i.e. a single-threaded non-atomic shared_ptr

Rust fans can dislike on the "C++ has no central library system like crates" all they want, but there's not many things you actually need when programming that don't exist for C++, even if you don't like them not coming in a little box that looks like other little boxes.

The point of the article isn't that single-threaded non-atomic shared pointers are unfeasible in C++, it is that their usage is too dangerous.

The fact that it wasn't included in the standard library for this reason is an argument for this. The fact that even `shared_ptr` has thread-safety footguns, one of which made it to the famous C++ talk, “Curiously Recurring C++ Bugs at Facebook”[1], is another. By the way, every single of the bugs from that talk is impossible in safe Rust.

[1]: https://youtu.be/lkgszkPnV8g?si=cCWASihvIGJ25Jf3

While we're at it, std::atomic<std::shared_ptr<T>>

https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic2

Yes, this is discussed in the article, I do not understand your point.

This. As soon as I need something it is quick online search away. Amount of stuff available for C++ is staggering

The criticism is less about what's available, for there is more available in C++ than Rust. The criticism is about ease of packaging in a cross-platform magnet that is easy enough.

Boost is extremely popular. I've used it in almost all my projects.

I have exactly zero problems using the same C++ code on Windows (debug and development) and then building and running it on Linux in production

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.