New C++ features in GCC 15

https://news.ycombinator.com/rss Hits: 1
Summary

The next major version of the GNU Compiler Collection (GCC), 15.1, is expected to be released in April or May 2025. Like every major GCC release, this version will bring many additions, improvements, bug fixes, and new features. GCC 15 is already the system compiler in Fedora 42. Red Hat Enterprise Linux (RHEL) users will get GCC 15 in the Red Hat GCC Toolset. It's also possible to try GCC 15 on Compiler Explorer and similar pages.Like my previous article, New C++ features in GCC 14, this article describes only new features implemented in the C++ front end; it does not discuss developments in the C++ language itself.The default dialect in GCC 15 is still -std=gnu++17. You can use the -std=c++23 or -std=gnu++23 command-line options to enable C++23 features, and similarly for C++26 and others. WarningNote that C++20, C++23, and C++26 features are still experimental in GCC 15. (GCC 16 plans to switch the default to C++20.)C++26 featuresC++26 features in GCC 15 include pack indexing, attributes for structured bindings, enhanced support for functions whose definition consists of =delete, and more.Pack indexingC++11 introduced variadic templates which allow the programmer to write templates that accept any number of template arguments. A pack can represent a series of types or values. For example, to print out arbitrary arguments, one could write:template<typename T, typename... Types> void print (T t, Types... args) { std::cout << t << '\n'; if constexpr (sizeof...(args) > 0) print (args...); } int main () { print ('a', "foo", 42); }However, it was not possible to index an element of a pack, unless the programmer resorted to using various recursive tricks which are generally slow to compile. With this C++26 feature, to index a pack one can write pack...[N] (where N has to be a constant expression). A pack index then behaves exactly as if the resulting expression was used. An empty pack cannot be indexed. The following program will print a:template<typename... Types> void...

First seen: 2025-04-25 11:54

Last seen: 2025-04-25 11:54