|C++ 20 Finalized|
|Written by Mike James|
|Wednesday, 16 September 2020|
C++ 20 has received final approval and the standard will be published by the end of the year. So it goes, languages grow and C++ seems to have no brake to slow it down.
C++ is a strange language. Whenever Bjarne Stroustrup explains C++ I think it is a well-designed, easy to use, and more importantly easy-to-understand langauge. Then I have to look at some C++ code written by another programmer, usually demo or library code and I think "What language is THIS!". C++ has grown so that there are at least two ways to do everything and as soon as you move away from the core of the language it gets very alien.
So it is with this in mind that I approach the new features introduced in C++ 20. The big thing seems to be modules, which are another level of encapsulation. A module can be imported and only the names explicitly exported in it are available for use. Well OK, but I don't think I really need it. As Herb Sutter puts it:
"Modules are a new alternative to header files that deliver a number of key improvements, notably isolating the effects of macros and enabling scalable builds."
Fine can we get rid of headers now? Shame we didn't start out with modules.
The second big thing is coroutines. I'm happy with threads, but then I'm offen accused of being so low level. A coroutine is much like you would find in other languages that don't fit so easily with threads. A coroutine is a function that can be suspended and resumed later. The reason it is part of the language, rather than a library, is that it is a stackless function which stores its state somewhere other than the stack. You can use coroutines to create async tasks, generators and lazy function. You can await a coroutine and yield while in a coroutine - how very Python.
The only other major feature is the "concept". Sounds good, but you know it's going to be tricky when you learn that it is an extension of the template idea. This is another one of those nice simple ideas when you first meet it. Then you bump into some implemented-by-a-template expert and you think "is this still C++?" and "how does that work?" Concepts let you specify constraints on template parameters that can be checked at compile time. It seems innocent enough, and it only slightly increases the complexity, and allows you control the use of templates, but I think it is probably going to be most used by template wizards.
So as the dust starts to settle the ISO committee has let slip that it has started work on C++ 23....
or email your comment to: firstname.lastname@example.org
|Last Updated ( Thursday, 17 September 2020 )|