C++ 20 Modern features

Josue Yenga
Game of Life
Published in
6 min readSep 9, 2020

--

If you have an opinion about C++, chances are you like it for its breadth and versatility, or dislike it for its inflated complexity and prefer to stick to alternative languages, C++ 20 has a lot to offer as announced last February by the ISO committee C++ 20 held its summer meeting in Cologne, Germany.

The minutes of the meeting indicate that work is complete for C++ 20 and a draft will be circulated before the end of the summer. During the meeting, some additions and changes were made to the C++ 20 draft presented by the committee in February.

As C++ 11 did, C++ 20 will change the way we program modern C++. This change is especially true for beaches, coroutines, concepts and modules. To understand this next big step in the evolution of C++, let me put it in this article in the historical context of the C++ standards.

C ++ 98

In the late 1980s, Bjarne Stroustrup and Margaret A. Ellis wrote the famous book Annotated C ++ Reference Manual (ARM). These books had two purposes. First, there were many independent C ++ implementations. So ARM defined the functionality of C ++. Second, ARM served as the basis for the first C++ standard: C++ 98 (ISO / IEC 14882). C ++ 98 had some important features: templates, the Standard Template Library (STL) with its containers and algorithms, strings and IO flows. For more information see these referents.

C ++ 03

With C ++ 03 (14882: 2003), C ++ 98 obtained a technical chronology correction. In the community, C ++ 03, which includes C ++ 98, is called inherited C++.

TR1

In 2005, something very interesting happened. The so-called TR1 technical report was published. TR1 was a big step towards C ++ 11 and, consequently, towards modern C ++. TR1 (TR 19768) is based on the Boost project which was founded by members of the C ++ standardization committee. TR1 to 13 libraries that should be part of the next C ++ standard. For example, the library to regular expression library, random number library, smart pointers such as std :: shared_ptr and hash tables. Only the so-called special mathematical functions had to wait for C ++ 17.

C ++ 11

C ++ 11 is the next C ++ standard, but we simply call it modern C ++. This name is also true for C ++ 14 and C ++ 17. C ++ 11 has many features that have fundamentally changed the way we program C ++. For example, C ++ 11 brought the components of the TR1, but also move-semantic, perfect forwarding, variadic models, or constexpr . But that’s not all. With C ++ 11, we have for the first time a memory model as the fundamental basis of threading and a threading API.

C ++ 14

C ++ 14 is a small C ++ standard. It brought read-write locks, generalized lambdas and generalized constexpr functions.

Trending Cryptocurrency Hub Articles:

1. Blockchain for Dummies in 4 minutes

2. Introduction to Cryptocurrencies: Dogecoin, the Most Bizarre Coin in the Cryptocurrency World

3. Google Enters The Blockchain Sector Through A Partnership

4. Blockchain use case: Trade Finance

C ++ 17

C ++ 17 is neither big nor small. It has two remarkable features: the parallel STL and the standardized file system. About 80 algorithms of the STL can be executed with a so-called execution policy. This means that an std :: sort call (std :: execute :: par, vec.begin (), vec.end ()) is a hint for the C ++ implementation to sort the vec container in parallel. In addition, you can specify that the sorting should be done sequentially ( std :: execution :: seq ), or vectorized ( std :: execution :: par_unseq ). As for C ++ 11, boost has also been very influential for C ++ 17. We got the boost file system and the three new data types: std :: option , std :: variant , and std :: all . Here are my messages to C ++ 17 .

C ++ 20

C ++ 20 will change the way we program C ++ as fundamentally as C ++ 11. This is especially true for the four major ones: ranges, coroutines, concepts and modules.

The new range library allows him to express algorithms directly on the container, to compose the algorithm with the pipe symbol and to apply them on infinite data flows.

Thanks to Coroutines, asynchronous programming in C ++ can become commonplace. Coroutines are the basis for cooperative tasks, event loops, infinite data streams or pipelines.

In any case, the list of new features is long, the combination of all the proposed specifications is even longer, and each of these additions could fill its own article in its own right. But to get a rough idea of what’s going to happen to C++ next year, let’s take a condensed look at some of the major new features, changes, and additions that await us in C++20

Here are some additional highlights:

  • the three-way comparison operator <=>
  • literal strings as model parameters
  • calendar and timezone extensions of the chrono library
  • std:: span as view on a contiguous array
  • fvirtual function constexpr
  • volatile redefinition
  • additions to atomic: std :: atomic_ref <T> and std :: atomic <std :: shared_ptr <T>>; while waiting for atomic
  • new synchronization mechanisms such as semaphores, locks and barriers
  • Constexpr containers such as std :: string and std :: vector
  • an improved std :: jthread, which joins automatically and can be stopped

However, this is not the end of the story, you can use predefined concepts or define your own.

Routing library

The range library is the first concept client. It supports algorithms that:

  • can run directly on the container; you don’t need iterators to specify a range
  • can be composed
  • To make a long story short: the range library supports functional models.

Coroutines

Coroutines are generalized functions that can be suspended and resumed while maintaining their state. Coroutines are the usual way to write event-driven applications. An event-driven application can be simulations, games, servers, user interfaces or even algorithms. Coroutines are also commonly used for cooperative multitasking .

We don’t get with the concrete coroutines C ++ 20; we will get a frame to write our coroutines. The framework for writing coroutines consists of more than 20 functions that you have to partially implement and that could partially overwrite.

Therefore, you can adapt the coroutine to your needs.

Conclusion

The C ++ is alive and occupies its own niche.

New standards introduce innovations that make the language simpler and more “user-friendly”. Software created with this language is still in use and requires support. C ++ is perfectly adapted to software development in certain areas, which, along with everything said above, means that C ++ is still necessary, evolving and will not give up.

Don’t forget to give us your 👏 !

--

--

Josue Yenga
Game of Life

Software Developer Focused on the Backend infrastructure, Open Source, Data Structures and Algorithms.