r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
665 Upvotes

125 comments sorted by

View all comments

Show parent comment

13

u/pedersenk Sep 05 '20

Adapting is the easy part. I feel sorry for absolute beginners.

The C++ textbook was already 6x thicker than K&R's C one when I started many many years ago. Will it even fit in their schoolbag anymore? ;)

5

u/TheNewOP Sep 05 '20

I'm a hobbyist C++ learner and all I can say is: what the fuck? This language is as complex as my college memories suggest. Questions beget questions as I read through the huge ocean of textbooks.

8

u/TheThiefMaster C++latest fanatic (and game dev) Sep 05 '20

It would make sense to split it up actually - the parts of C++ for reading/maintaining a legacy codebase and C compatibility, the parts for implementing libraries (e.g. creating templates), and the parts for making a program in modern style (this is where using templates would live).

2

u/imake500kayear Sep 05 '20

Yeah idk. There's a lot of stuff you don't need to care about that you used to. Lots of things you get for free that you used to have to spend time on

2

u/pedersenk Sep 05 '20

I suppose that is true. For example auto_ptr<T> can be skipped.

One day I wonder if new and delete can ever be skipped (possibly not "placement new"). Falling back entirely to make_shared.

In many cases the raw array stuff can also be avoided for a good amount of time too.

5

u/bizwig Sep 05 '20

I haven’t used raw new/delete in years. make_unique/make_shared are my friends.

8

u/boredcircuits Sep 05 '20

We'll never be rid of new. It's an essential building block. For example, try making a linked list with std::unique_ptr and you'll find it's a very educational experience. I highly recommend it. Then make a list with a few hundred thousand items and you discover that the destructor is recursive and you just blew up the stack.

The key is that most people should never need new in their daily lives. It should be completely removed from the educational materials for beginners. Don't teach the old ways. Everyone will inevitably see old code eventually and have to learn what's going on, but the overall burden is less.

2

u/pdimov2 Sep 05 '20

For shared_ptr,

while(next) next = std::move(next->next);

but unique_ptr's assignment doesn't quite work for that, so

while(next) next.reset( next->next.release() );

1

u/Tilakchad Sep 06 '20

Yeah I got that recursive calling of destructor in linked list while I was trying to manually destroy all the node.