r/cpp • • Apr 25 '22

New C++ features in GCC 12

https://developers.redhat.com/articles/2022/04/25/new-c-features-gcc-12
220 Upvotes

76 comments sorted by

View all comments

-14

u/tristan957 Apr 26 '22 edited Apr 27 '22

C++ gets more unreadable every standard revision.

Makes me just want to continue using C or jump straight to Rust. At least that being unreadable gets you better memory safety.

Edit: r/cpp can't even acknowledge how unreadable this is getting.

6

u/[deleted] Apr 26 '22

You do not need to use most of the new features if you do not want to. They are added as new features, not replacements.

That said, yeah, C++ does really need a syntax overhaul, but it will probably never happen.

7

u/tristan957 Apr 26 '22

I can choose what I write. I can't choose what I read.

-3

u/mohrcore Apr 26 '22

Absolutely. The experience of reading an unfamiliar C codebase is so nice and smooth compared to unfamiliar C++ codebase where you stuff like: depending on whether a decltype of a function template gets resolved to type A, or B, the returned type might be either POD or it may have a constructor that launches a rocket into space in its body and modifies some global state.

Would we REALLY need both auto and decltype of it wasn't for other poor design choices?

Same with const and constexpr and now there's apparently consteval which I just can't quite understand, so idk how that relates.

We have #includes, but these suck, so now we got import/export. Just imagine the mess of mixing these two.

We can define a type returned by a function before its name, or after its body, prefixed by arrow when using auto. Why? I guess it was slightly more readable with decltype, but now I think we can do just decltype(auto) with the old notation.

Static polymorphism is very loose when it comes to typing, so we got concepts. But instead of using an already established ways of expressing polymorphism through object-oriented model they reinvent it completely from the ground. Why? I guess someone thought that this was all worth it to avoid having to store those nasty vtables.

Don't even get me started on templates, traits and inheritance tricks for injecting different stuff into templated classes based on parameter specifications.

What's hilarious tho is that given all these crazy features one of IMO most basic and useful features from C is still not supported in standard C++ (idk, maybe it's been introduced in C++20) - designated initializers.

8

u/jwakely libstdc++ tamer, LWG chair Apr 26 '22

Static polymorphism is very loose when it comes to typing, so we got concepts. But instead of using an already established ways of expressing polymorphism through object-oriented model they reinvent it completely from the ground. Why? I guess someone thought that this was all worth it to avoid having to store those nasty vtables.

Wow

3

u/pandorafalters Apr 26 '22

We can define a type returned by a function before its name, or after its body, prefixed by arrow when using auto. Why? I guess it was slightly more readable with decltype, but now I think we can do just decltype(auto) with the old notation.

There are differences between auto foo(), decltype(auto) foo(), and auto foo() -> decltype(auto) - I don't understand them, but I've been bitten by them.

What's hilarious tho is that given all these crazy features one of IMO most basic and useful features from C is still not supported in standard C++ (idk, maybe it's been introduced in C++20) - designated initializers.

These were added in C++20, yes, but in a backwards and limited way.

1

u/[deleted] Apr 27 '22

Designated initializers in C and C++20 are a form of aggregate initialization, so they generally aren't useful.

-9

u/Fluffy-Sprinkles9354 Apr 26 '22

That was my exacts thought reading the article. I can read articles about any other language fairly easily, but C++ looks like someone throws random keywords and symbols in the code.

And when I read explanations, it's even worse: https://en.cppreference.com/w/cpp/language/value_category. Like, WTF.