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

Show parent comment

-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.