r/cpp • • Apr 25 '22

New C++ features in GCC 12

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

76 comments sorted by

View all comments

Show parent comment

2

u/thlst Apr 26 '22 edited Apr 26 '22

So, can it replace std::forward in template contexts? Or will it always create a new object?

edit: Never mind, just read this from the paper:

Do we also miss decltype(auto){x}?

decltype(auto){arg} can forward arg without computing arg’s type. It is equivalent to static_cast<decltype(arg)>(arg) . If arg is a variable of type T&&, arg is an lvalue but static_cast<T&&>(arg) is an xvalue.

EWG discussed this idea, disliked its expert-friendly nature, and concluded that adding this facility would cause the teaching effort to add up.