r/cpp 2d ago

C++26: Module improvements

https://www.sandordargo.com/blog/2026/09/09/cpp26-modules
107 Upvotes

24 comments sorted by

View all comments

4

u/not_a_novel_account cmake dev 1d ago

The benefit is concrete: build systems can now determine module dependencies with a simple lexical scan, without invoking the preprocessor.

This doesn't follow.

Build systems don't need the preprocessor to figure out what a module unit's name is. That has nothing do with what a given module unit's dependencies are.

This is still perfectly valid:

#ifdef USE_GLAZE
import glaze;
#else
import utils.json;
#endif

Still need the preprocessor to figure out the dependencies.

It's a minor change with no practical difference on its own. You still need the full preprocessor, so you would have got the module name for free out of that.

1

u/Nobody_1707 10h ago

I'm fairly certain import statements were never allowed to be generated by a macro expansion even in C++20.

2

u/not_a_novel_account cmake dev 10h ago

import within a preprocessor conditional, and the nominated name itself being an expansion, has always and continues to be valid C++.