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.

cplus

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.

The bottom line is that we can now start thinking how to use modules to control the visibility of names in classes, data and functions. Coroutine use is clearly going to be a way of sniffing out those programmers who would most likely feel more at home in Python or JavaScript.

So as the dust starts to settle the ISO committee has let slip that it has started work on C++ 23....

 cplus

<ASIN:0321992784>

<ASIN:0321563840>

<ASIN:1871962420>

<ASIN:1871962587>

<ASIN:1871962536>

<ASIN:1871962404>

 

More Information

C++20 approved, C++23 meetings and schedule update

Related Articles

C++ Picked Out By TIOBE - An Odd Choice?

Bjarne Stroustrup On Why Learn C++

C++ 20 Feature List Finalized

Bjarne Stroustrup Thinks He Has A Better Way To Do Generics

C++ Where Is It Heading? C++17

C++ 14 Approved

In Praise Of C++ Bjarne At ICPC

Why your next language better be C++ 

The Irrelevance of the New C++ Standard

Towards Objects and Functions - Computer Languages In The 1980s

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Conference Times Ahead
29/03/2024

Following a well-established pattern both Google's and Microsoft's Developer Conferences will take place in May while Apple follows on in June. Here are the dates plus what to expect.



Pulumi Adds Infrastructure Lifecycle Management Features
25/04/2024

Pulumi has added new infrastructure lifecycle management features to Pulumi Deployments, its deployments and workflow product.


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info

 

Last Updated ( Monday, 21 September 2020 )