News for hackers. Stuff that matters.
Re:Embracing Modern C++ Safely, Book Review by arinlen on Monday May 30, 2022 @02:19PM (#31561927)
> The trouble with "Modern C++" is that nothing gets deleted from "Classic C++".

This is not exactly true. For example, with the introduction of smart pointers, manual memory management is kicked out of C++'s happy path. This makes code far simpler to reason about and safer. Sure, you can still use new and delete, but since C++11 you better have a very good reason to use those.

Nevertheless, it doesn't make sense to complain about not deleting stuff from C++ when a) until recently C++ was repeatedly criticized for having an extremely spartan standard library, b) since C++98 basic features were added to C++ such as support for parallel and concurrent programming, c) there is no feature that gathers anything resembling a consensus on beig worth taking out of the standard.

I'd add that pseudo-standard libraries for C++, such as Boost and POCO, have been popping up and growing in both scope and adoption. This reflects a clear need felt by the C++ community to increase the scope of it's standard components.

Re:Embracing Modern C++ Safely, Book Review by oncewas on Monday May 30, 2022 @07:02PM (#31564553)
Outside of the happy path doesn't mean, inaccessible or uncommonly used. C++ is on track to be a composition of ten languages by 2030. I'm not against that in general, it's kind of liberating, but at some point in time I hope someone does decide to do some house keeping.
Re:Embracing Modern C++ Safely, Book Review by Animats on Monday May 30, 2022 @02:30PM (#31562024)
There are too many APIs that still want raw pointers.
Re:Embracing Modern C++ Safely, Book Review by arinlen on Monday May 30, 2022 @02:34PM (#31562085)
> There are too many APIs that still want raw pointers.

Irrelevant. C++'s smart pointers deal with ownership and life cycle management. You can still pass raw pointers to objects managed by a smart pointers.

The only exception is when you're dealing with a framework which already handles life cycle management, such as Qt. Nevertheless, even Qt offers its own smart pointers suite.

Re:Embracing Modern C++ Safely, Book Review by UncleMeat on Monday May 30, 2022 @05:50PM (#31564000)
> You can still pass raw pointers to objects managed by a smart pointers.

Not if the API is taking ownership and you want your program to be correct. This happens far more often than dealing with something like Qt.

Re:Embracing Modern C++ Safely, Book Review by rtpg on Monday May 30, 2022 @10:25PM (#31565545)
If the API takes ownership, can't you just release the smart pointer, effectively forgetting about it and letting the new owner deal with it? Maybe I'm missing somethign.
Re:Embracing Modern C++ Safely, Book Review by UncleMeat on Tuesday May 31, 2022 @09:52AM (#31569480)
That means it is no longer managed by a smart pointer and you need to understand the nature of the API. I understood the above comment to mean that you can just solve problems by calling "get" and moving on with your life.
Re:Embracing Modern C++ Safely, Book Review by Koshkin on Monday May 30, 2022 @04:41PM (#31563416)
There's nothing wrong with using a raw pointer as an argument of a function. In this context this is usually equivalent to using a reference. What is wrong, in fact, is passing, instead, a unique pointer (by reference, necessarily) or, even worse, a shared pointer (by value) when there is no need for sharing.
Re:Embracing Modern C++ Safely, Book Review by PaulDavisThe1st on Monday May 30, 2022 @11:22PM (#31565803)
> In this context this is usually equivalent to using a reference.

Not really. The very, very, very important difference is that the pointer can be null, signalling "no object". For some purposes, this is a critically important difference; in other cases, you should be passing a reference.

Re:Embracing Modern C++ Safely, Book Review by cjaybo on Monday May 30, 2022 @02:38PM (#31562126)
Even if they want to take ownership, smart pointers allow the semantics to be expressed clearly and in a safe manner.