Can we finally use C++ Modules in 2026?
18 points by raymii
18 points by raymii
Using modules exclusively now, including import std. The ecosystem is almost there. Big compilers [1] agreeing to back port it to C++20 and foundational libs like vulkan hpp supporting it [2]. There are still misunderstandings with build system integration [3] and clangd still needs a full recompile before it sees an update to a module, which messes with productivity. I for one, am not going back.
[1] https://github.com/microsoft/STL/issues/1694#:~:text=informal%20agreement
[2] https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#v14334
[3] https://gitlab.kitware.com/cmake/cmake/-/work_items/27706
How is meson support? Or support with other decent build systems? CMake seems like it's the farthest along, and I'm not moving to cmake just to be able to replace #import with include
And how far along are with solving the circular dependencies issue? With includes, I can have modules A and B, A.h can forward declare class B, A.cpp can #incude "B.h", and B can #include "A.h". This is pretty common, especially with tree structures where a parent owns a child but the child wants a pointer to its parent. Presumably there's now a way to port this to C++ modules?
No.
I tried to convert a project to C++ modules recently and had to abandon it because I was getting a mismatch between clangd bundled with my IDE and clang tools being used by my project. The intermediate formats involved aren't standardized and can change between releases of clang so it's quite brittle. My IDE just showed hundreds of nonsensical errors.
clangd bundled with my IDE and clang tools being used by my project
BMI incompatibility is a known issue: https://youtu.be/_LGR0U5Opdg?si=afNdyCVOiguWsoHQ&t=1276 I do wonder whether compilers will get it together in coming versions.
I've started to use Modules in one of my projects. So far, it's been a smooth experience, but I haven't used import std or any libraries using it. Probably import std will be the biggest friction to adopting modules at the current stage.
import std is probably the most useful part of modules IMO. Includes work fine for libraries, but it's so easy to miss includes or accidentally rely on incidental inclusions in the stdlib.