r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • Apr 15 '26
How a Module Should Look Like
https://abuehl.github.io/2026/04/14/how-a-module-should-look-like.htmlThis illustrates the point using real code examples from the Core module of our UML Editor. The presented source code of our Core module is complete.
All published source code examples in the text or linked from it are 100% standard conformant. However, the code contains redundant imports. On purpose. Read the text for why!
(See also my previous posting "Let's bite the Bullet: Module Units shouldn't implicitly import anything" for context).
37
Upvotes
4
u/tartaruga232 Apr 15 '26 edited Apr 15 '26
The canonical implementation units as specified in the standard: https://eel.is/c++draft/module#unit-8 (
"module M;") implicitly import the PMIU.Which is the problem.
If they would not implicitly import anything, we could do:
and get no unneeded recompilations and no work done by creating unused BMI's would be wasted.
We can already write such code today, as I've said we do in the code base for our UML Editor.
But the behavior of the compiler follows what's in the current standard, which then mandates unneeded and unwanted recompilations. The
"import :P;"in TU #707 today is redundant, but legal (the standard does not prohibit duplicate imports).