The last big feature of C++ we'll discuss in this chapter is modules. They are yet one more addition to C++20 that has a great impact on building and partitioning code.
C++ has used #include for a really long time now. However, this textual form of dependency inclusion has its flaws, as listed here:
- Due to the need to process lots of text (even a Hello World after preprocessing is around half a million lines of code), it's slow. This leads to one-definition rule (ODR) violations.
- The order of your includes matters, but it shouldn't. This one is twice as bad as the preceding one as it also leads to cyclic dependencies.
- Finally, it's hard to encapsulate stuff that just needs to be in header files. Even if you put some stuff in a detailed namespace, someone will use it, as Hyrum's law predicts.
Fortunately, this is when modules enter the game. They should solve the aforementioned flaws, bringing a great speedup to build times and better...