What are the C++20 Modules?
Module is quite an overloaded word in the context of C++ builds. We previously discussed modules in this book in the context of CMake: find-modules, utility modules, and such. Let's clarify that C++ modules have nothing to do with CMake modules. Instead, they are a native feature of the language added in the C++20 version.
At its core, a C++ module is a single source file that encapsulates the functionality of headers and implementation files into one coherent unit of code. It compiles into two primary components:
- Binary Module Interface (BMI) serves a similar purpose to a header file but is in a binary format, significantly reducing the need for recompilation when consumed by other translation units.
- Module Implementation Unit provides the implementation, definitions, and internal details of the module. Its contents are not directly accessible from outside the module, effectively encapsulating the implementation details.
Modules were introduced to reduce...