Skip to content

Commit ea07f8f

Browse files
TylerMSFTTylerMSFT
authored andcommitted
finish draft
1 parent 43bdd91 commit ea07f8f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/build/compare-inclusion-methods.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Header units were introduced as a way to temporarily bridge the gap between head
1717

1818
Then, the C++23 standard library introduced support for importing the standard library as named modules--which is the fastest and most robust way to consume the standard library.
1919

20-
To help you sort out the different options, this article compares the traditional `#include` method against precompiled headers, header units, and the `std` and `std.compat` named modules.
20+
To help you sort out the different options, this article compares the traditional `#include` method against precompiled headers, header units, and importing the `std` and `std.compat` named modules.
2121

2222
The following table is arranged by compiler processing speed and robustness, with `#include` being the slowest and least robust, and `import` being the fastest and most robust.
2323

@@ -28,11 +28,11 @@ The following table is arranged by compiler processing speed and robustness, wit
2828
| [Header units](../build/walkthrough-header-units.md) | This is a new feature in C++20 that allows you to import 'well-behaved' header files as modules. Header units are faster than `#include`, and are easier, significantly smaller, and faster than pre-compiled header files (PCH). Header units are an 'in-between' step meant to help transition to named modules in cases where you rely on macros defined in header files, since named modules don't expose macros. Header units are slower than importing a named module. Header units aren't affected by macro defines unless they're specified on the command line when the header unit is built--making them more robust than header files. Header units expose the macros and internal implementation defined in them just as header file do, which named modules don't. As a rough approximation of file size, a 250-megabyte PCH file might be represented by an 80-megabyte header unit file. |
2929
| [Modules](../cpp/modules-cpp.md) | This is the fastest and most robust way to import functionality. Support for importing modules was introduced in C++20. The C++23 standard library introduces the two named modules described in this topic. When you import `std`, you get the standard names such as `std::vector`, `std::cout`, but no extensions, no internal helpers such as `_Sort_unchecked`, and no macros. The order of imports doesn't matter because there are no macro or other side-effects. As a rough approximation of file size, a 250-megabyte PCH file might be represented by an 80-megabyte header unit file, which might be represented by a 25-megabyte module. The reason named modules are faster is because when a named module is compiled into an `.ifc` file and an `.obj` file, the compiler emits a structured representation of the source code that can be loaded quickly when the module is imported. The compiler can do some work (like name resolution) before emitting the `.ifc` file because of how named modules are order-independent and macro-independent--so this work doesn't have to be done when the module is imported. In contrast, when a header file is consumed with `#include`, its contents must be preprocessed and compiled again and again in every translation unit. Precompiled headers, which are compiler memory snapshots, can mitigate those costs, but not as well as named modules. |
3030

31-
If you can use C++20 features and the C++23 standard library, use named modules.
31+
If you can use C++20 features and the C++23 standard library in your app, use named modules.
3232

3333
If you can't use C++20 features, use header units. If you can't use C++20 features or header units, use precompiled headers.
3434

35-
If you can't use C++20 features, header units, or precompiled headers, you're left with `#include`, which is the slowest and least robust method.
35+
If you can't use C++20 features, header units, or precompiled headers, use `#include`.
3636

3737
## See also
3838

docs/cpp/tutorial-import-stl-named-module.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ C++20 introduces a modern alternative called *modules*. In C++23, we were able t
4747

4848
Like header files, modules allow you to share declarations and definitions across source files. But unlike header files, modules aren't fragile and are easier to compose because their semantics don't change due to macro definitions or the order in which they're imported. The compiler can process modules significantly faster than it can process `#include` files, and uses less memory at compile time as well. Macro definitions defined in a named module aren't exposed, nor are private implementation details.
4949

50-
For in depth information about modules, see [Overview of modules in C++](../build/modules-cpp.md) That article also discusses consuming the C++ standard library as modules, but uses an older and experimental way of doing it.
50+
For in depth information about modules, see [Overview of modules in C++](modules-cpp.md) That article also discusses consuming the C++ standard library as modules, but uses an older and experimental way of doing it.
5151

52-
This article demonstrates the new and best way to consume the standard library. For more information about alternative ways to consume the standard library, see [Different ways to consume the standard library](#different-ways-to-consume-the-standard-library).
52+
This article demonstrates the new and best way to consume the standard library. For more information about alternative ways to consume the standard library, see [Compare header units, modules, and precompiled headers](../build/compare-inclusion-methods.md).
5353

5454
## Import the standard library with `std`
5555

0 commit comments

Comments
 (0)