'What exactly are C++ modules?

I've been following up C++ standardization and came across C++ modules idea. I could not find a good article on it. What exactly is it about?



Solution 1:[1]

C++ modules are proposal that will allow compilers to use "semantic imports" instead of the old text inclusion model. Instead of performing a copy and paste when a #include preprocessor directive is found, they will read a binary file that contains a serialization of the abstract syntax tree that represents the code.

These semantic imports avoid the multiple recompilation of the code that is contained in headers, speeding up compilation. E.g. if you project contains 100 #includes of <iostream>, in different .cpp files, the header will only be parsed once per language configuration, rather than once per translation unit that uses the module.

Microsoft's proposal goes beyond that and introduces the internal keyword. A member of a class with internal visibility will not be seen outside of a module, thus allowing class implementers to hide implementation details from a class. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4465.pdf

I wrote a small example using <iostream> in my blog, using LLVM's module cache: https://cppisland.wordpress.com/2015/09/13/6/

Solution 2:[2]

Please take a look at this simple example I love. The modules there are really good explained. The author uses simple terms and great examples to examine every aspect of the problem, stated in the article.

https://www.modernescpp.com/index.php/c-20-modules

Solution 3:[3]

Here is one of the first propositions : http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1778.pdf

And a very good explanation : http://clang.llvm.org/docs/Modules.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Stf Kolev
Solution 3 Jean-Michaël Celerier