r/cpp • 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.html

This 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

17 comments sorted by

View all comments

Show parent comment

5

u/not_a_novel_account cmake dev Apr 15 '26

Do you know what is the reasoning behind the "implicit imports"?

Because the standard forbids implementation units from importing the PMIU of the same name.

You can't import the declarations from the PMIU into an implementation unit, because it's forbidden. So the standard solves for this by mandating the PMIU is implicitly imported.

Things got a little off the rails here. Implementation units are suitable for small modules consisting of just a PMIU and a handful of definitions, but forbidding implementation units from importing the PMIU turned out to be pointless. In fact it actually works without error on most implementations today.

Partitions were the solution to larger modules. The partition version of implementation units got its wires crossed and became half interface, half implementation file, and isn't good at either.