{"id":5793,"date":"2019-10-17T20:54:11","date_gmt":"2019-10-17T20:54:11","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/c-20-an-overview\/"},"modified":"2019-10-17T20:54:11","modified_gmt":"2019-10-17T20:54:11","slug":"c-20-an-overview","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c-20-an-overview\/","title":{"rendered":"The Next Big Thing: C++20"},"content":{"rendered":"<p>C++20 will be the next big C++ standard after C++11. As C++11 did, C++20 will change the way we program modern C++. This change is particularly true for Ranges, Coroutines, Concepts, and Modules.&nbsp;To understand this next big step in the evolution of C++, let me put it in this post in the historical context of C++ standards.<\/p>\n<p><!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5791\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/10\/TimelineCpp.png\" alt=\"TimelineCpp\" width=\"600\" height=\"245\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/10\/TimelineCpp.png 996w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/10\/TimelineCpp-300x123.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/10\/TimelineCpp-768x314.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_C_Standards\"><\/span>The C++ Standards<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<div>&nbsp;<\/div>\n<div>C++ is about 40 years old. What happened in the last years? Here is a simplified answer which emphasizes C++20.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C98\"><\/span>C++98<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>At the end of the 80ths, Bjarne Stroustrup and <span data-ved=\"0ahUKEwj1rL2Us6XlAhXDZlAKHV4_B1UQ2koIywEoAjAM\">Margaret A. Ellis <\/span>wrote their famous book <a href=\"http:\/\/www.stroustrup.com\/arm.html\">Annotated C++ Reference Manual <\/a>(ARM). These books served two purposes. First, there were many independent C++ implementations. ARM defined, therefore, the functionality of C++. Second, ARM was the base for the first C++ standard: C++98 (ISO\/IEC&nbsp;14882). C++98 had a few important features: templates, the standard template library (STL) with its containers and algorithms, strings, and IO streams.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C03\"><\/span>C++03<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>With C++03 (14882:2003), C++98 got a technical correction that is so small that there is no place on my timeline. In the community, C++03, which includes C++98, is called legacy C++.&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"TR1\"><\/span>TR1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In 2005 something exciting happened. The so-called technical report 1 (TR1; ) was published. TR1 was a big step toward C++11 and, therefore, toward Modern C++. TR1 (TR 19768) is based on the <a href=\"https:\/\/www.boost.org\/\">boost project<\/a> founded by members of the C++ standardization committee. TR1 has 13 libraries that should become part of the next C++ standard. For example, the library to the regular expression library, the random number library, smart pointers such as <span style=\"font-family: courier new, courier;\">std::shared_ptr<\/span>, and hashtables. Only the so-called special mathematic functions had to wait until C++17.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C11\"><\/span>C++11<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>C++11 stands for the next C++ standard, but we call it Modern C++. This name also holds for C++14 and C++17. C++11 has many features which fundamentally changed the way we program C++.&nbsp; For example, C++11 brought the components of the TR1, but also move-semantic, perfect forwarding, variadic templates, or constexpr<span style=\"font-family: courier new, courier;\">.<\/span> But this is not all. With C++11, we got a memory model as the fundamental threading base and a threading API. If you are curious, here are my post on the <a href=\"https:\/\/www.modernescpp.com\/index.php\/category\/multithreading-memory-model\">memory model<\/a> and <a href=\"https:\/\/www.modernescpp.com\/index.php\/category\/multithreading\">multithreading<\/a> in general.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C14\"><\/span>C++14<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>C++14 is a small C++ standard. It brought read-writer locks, generalized lambdas, and generalized constexpr functions.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"C17\"><\/span>C++17<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>C++17 is neither big nor small. It has two outstanding features: the parallel STL and the standardized filesystem. About 80 algorithms of the STL can be executed with a so-called execution policy. This means a call<span style=\"font-family: courier new, courier;\"> std::sort(std::execute::par, vec.begin(), vec.end())<\/span> is a hint for the C++ implementation to sort the container vec in a parallel way. Additionally, you can specify that the sort should be done sequentially (<span style=\"font-family: courier new, courier;\">std::execution::seq<\/span>) or vectorized (<span style=\"font-family: courier new, courier;\">std::execution::par_unseq<\/span>). As for C++11, boost was also highly influential for C++17. We got the filesystem from boost and the three new data types: <span style=\"font-family: courier new, courier;\">std::optional<\/span><span style=\"font-family: courier new, courier;\">, std::variant<\/span><span style=\"font-family: courier new, courier;\">,<\/span> and <span style=\"font-family: courier new, courier;\">std::any<\/span><span style=\"font-family: courier new, courier;\">. <\/span>Here are my posts to <a href=\"https:\/\/www.modernescpp.com\/index.php\/category\/c-17\">C++17<\/a>.<span style=\"font-family: courier new, courier;\"><br \/><\/span><\/p>\n<h3><span class=\"ez-toc-section\" id=\"C20\"><\/span>C++20<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>C++20 will change the way we program C++ as fundamentally as C++11. This holds, in particular, for the big four: Ranges, Coroutines, Concepts, and Modules. A half year ago, I would write the big five, but contracts were removed in the standardization meeting this year in Cologne. A contract specifies in a precise and checkable way interfaces for software components. My post, <a href=\"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-a-detour-to-contracts\">C++ Core Guidelines: A Short Detour to Contracts in C++20<\/a>, gives you more details. I should not write about the past. Here is the bright shining, upcoming future.<\/p>\n<p>The new ranges library enables it to express algorithms directly on the container, compose the algorithm with the pipe symbol and apply them to infinite data streams.<\/p>\n<p>Thanks to Coroutines, asynchronous programming in C++ may become mainstream. Coroutines are the base for cooperative tasks, event loops, infinite data streams, or pipelines.<\/p>\n<p>Concepts will change the way we think and program templates. They are semantic categories for valid template arguments. They enable you to express your intention directly in the type of system. If something goes wrong, you will get a short error message.<\/p>\n<p>Modules will overcome the restrictions of header files. They promise a lot. For example, the separation of header and source files becomes as obsolete as the preprocessor. Ultimately, we will also have faster build times and an easier way to build packages.<\/p>\n<p>But this by far not all. Here are a few additional highlights:<\/p>\n<ul>\n<li>the three-way comparison operator<span style=\"font-family: courier new, courier;\"> &lt;=&gt;<\/span><\/li>\n<li>strings literals as template parameters<\/li>\n<li>calendar and time-zone extensions of the chrono library<\/li>\n<li><span style=\"font-family: courier new, courier;\">std:<\/span>:span as a view on a contiguous array<\/li>\n<li>constexpr virtual function<\/li>\n<li>redefinition of <span style=\"font-family: courier new, courier;\">volatile<\/span><\/li>\n<li>additions to the atomics: <span style=\"font-family: courier new, courier;\">std::atomic_ref&lt;T&gt;<\/span> and <span style=\"font-family: courier new, courier;\">std::atomic&lt;std::shared_ptr&lt;T&gt;&gt;;&nbsp;<\/span>waiting on atomics<\/li>\n<li>new synchronization mechanisms such as semaphores, latches, and barriers<\/li>\n<li>constexpr containers such as <span style=\"font-family: courier new, courier;\">std::string<\/span> and <span style=\"font-family: courier new, courier;\">std::vector<\/span><\/li>\n<li>an improved thread <span style=\"font-family: courier new, courier;\">std::<\/span>jthread, which joins automatically and can be stopped<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Naming\"><\/span>Naming<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Okay, we should give the new child a name because the existing C++ standards have all informal names.<\/p>\n<ul>\n<li>Legacy C++: C++98, and C++03<\/li>\n<li>Modern C++: C++11, C++14, and C++17<\/li>\n<li>&lt;To be filled&gt;: C++20, C++23 &#8230;<\/li>\n<\/ul>\n<p>This name discussion is difficult. In April, I had the same question on Twitter. Here is the tweet,<\/p>\n<blockquote class=\"twitter-tweet\">\n<p dir=\"ltr\" lang=\"en\">How should we call C++20 and the beyond area? <br \/>C++98 &#8211; C++03: Legacy C++<br \/>C++11 &#8211; C++17: Modern C++<br \/>C++20 &#8211; C++.. : <br \/>Honestly, I don&#8217;t know.<\/p>\n<p>\u2014 Rainer Grimm (@rainer_grimm) <a href=\"https:\/\/twitter.com\/rainer_grimm\/status\/1122529834276675584?ref_src=twsrc%5Etfw\">April 28, 2019<\/a><\/p><\/blockquote>\n<p>and here are a few more than 50 answers. I added the Twitter names to the suggestions.<\/p>\n<div>\n<ul>\n<li>indifferent penguin: Postmodern<\/li>\n<li>Ricardo: next generation<\/li>\n<li>Robert Ramey: The end of days<\/li>\n<li>Daniel Oliveira: C++ Reloaded\/Revolution\/Exoteric<\/li>\n<li>Michele Adduci: postmodern, post-postmodern, post-post-postmodern and so on<\/li>\n<li>Thomas Rodgers: C++ Endgame<\/li>\n<li>phlo81: new C++<\/li>\n<li>Eric Niebler: co_modular C++<\/li>\n<li>Martin Moene: Simple C++<\/li>\n<li>Andrey Upadyshev: C++ 2<\/li>\n<li>Joel F: Neon Genesis C++<\/li>\n<li>Breno G: C+=2<\/li>\n<li>Rasmus &#8216;Elg&#8217; Bons: Futuristic C++<\/li>\n<li>Sebastian Rampe: new c++<\/li>\n<li>Dr James Smith: C++ Plus, C++ The Next Generation, C+++<\/li>\n<li>Richard Robinson: ++C<\/li>\n<li>Saurabh Purnaye: Ultra Modern cpp<\/li>\n<li>Alican G\u00fcltekin: C+++<\/li>\n<li>Alfonso Guerra: Neo-Futuris<\/li>\n<li>Improv: now C++<\/li>\n<li>Chris Blume Moderner C++<\/li>\n<li>Satay Das: New modern C++<\/li>\n<li>JustXtofl: post-20<\/li>\n<li>Adem Budak: Postconceptual C++<\/li>\n<\/ul>\n<p>You see, there is a slight tendency to be postmodern. Maybe, you have a better idea.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Whats_next\"><\/span>What&#8217;s next?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now, the questions challenged me the most. I have written ten posts in the last few years, with C++20 as their topic. My question was: Should I link to my existing posts or publish them again? The first way is incomplete, and the second way is redundant. I decided to pursue a third way. If possible, I will use the existing posts as a starting post but write them new. The reason is simple. First, I assume most of you don&#8217;t know my posts older than one year. Second, many of the features have changed since I wrote about them. My overall idea is to give you a complete post-series to C++20. Of course, I start with the big four.<\/p>\n<p>The <a href=\"https:\/\/www.modernescpp.com\/index.php\/der-einstieg-in-modernes-c\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5792\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2019\/10\/StartHere.png\" alt=\"StartHere\" width=\"200\" height=\"50\" style=\"vertical-align: middle;\" \/><\/a>button in the right corner of this blog guides you to the overview of my existing and upcoming C++20 posts.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++20 will be the next big C++ standard after C++11. As C++11 did, C++20 will change the way we program modern C++. This change is particularly true for Ranges, Coroutines, Concepts, and Modules.&nbsp;To understand this next big step in the evolution of C++, let me put it in this post in the historical context of [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":5791,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[375],"tags":[],"class_list":["post-5793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-20"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5793"}],"version-history":[{"count":0,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5791"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}