What to expect with C++20

Pages: 123
Bjarne Stroustrup wrote:
The modules should with a bit of luck improve our compile speeds by say five to ten times [...] The way you get that major compile time advantage is by cleaning up your code, removing disgusting dependencies, saving the compiler from compiling the same thing ten times over because you might have a macro that is different.
https://youtu.be/u_ij0YNkFUs?t=1h22m55s

I'm still a bit skeptical but what he says is interesting. Maybe modules will force me to structure my code in a better way. We'll see.
Last edited on
The Modules idea is sound, but how (and when) it is implemented by the various compilers will be the real test IMO.

Many of the compilers are already supporting various parts of what will become the next standard. I know MSVS already does have Modules as experimental, but to use the feature code has to turn off a few warnings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// need to enable C+ Modules (experimental) and use C++17 or latest language standard

// example copied from
// https://blogs.msdn.microsoft.com/vcblog/2017/05/05/cpp-modules-in-visual-studio-2017/

#pragma warning(disable : 5050)  // to disable uncaught_exception warning

import std.core;

#pragma warning(disable : 4996)  // to disable uncaught_exception warning

int main()
{
   std::vector<std::string> v { "Plato", "Descartes", "Bacon" };
   std::copy(v.crbegin(), v.crend(), std::ostream_iterator<std::string>(std::cout, "\n"));
}


The example I tested was over 2 years old, it looks like MS has now fixed the problem with using Modules in 2019. The code sample originally had the #pragmas. VS 2017 still needs them.

Whether Modules speeds up compilation I can't say. Based on this simple code snippet Modules will make it easier to use standard library features without the headache of needing multiple headers.
Last edited on
Topic archived. No new replies allowed.
Pages: 123