Skip to content

Commit 72084ff

Browse files
Merge pull request #4704 from TylerMSFT/m
address github #4319
2 parents dcb855a + 177d5d4 commit 72084ff

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Tutorial: Import the standard library (STL) using modules (C++)"
3-
ms.date: 12/01/2022
3+
ms.date: 12/02/2022
44
ms.topic: "tutorial"
55
author: "tylermsft"
66
ms.author: "twhitney"
@@ -9,7 +9,7 @@ description: Learn how to import the C++ standard library (STL) using modules
99
---
1010
# Tutorial: Import the C++ standard library using modules
1111

12-
Learn how to import the C++ standard library using C++ library modules. Which is significantly faster to compile and more robust than using header files or header units or precompiled headers (PCH).
12+
Learn how to import the C++ standard library using C++ library modules. This is significantly faster to compile and more robust than using header files or header units or precompiled headers (PCH).
1313

1414
In this tutorial, learn about:
1515

@@ -45,15 +45,15 @@ Header files are how declarations and definitions have been shared between sourc
4545

4646
C++20 introduces a modern alternative called *modules*. In C++23, we were able to capitalize on module support to introduce named modules for the standard library.
4747

48-
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.
48+
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 you import them. 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

5050
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

5252
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

56-
The following demonstrates how to consume the standard library as a module using the command line compiler. The Visual Studio IDE experience for importing the standard library as a module is still being implemented.
56+
The following examples demonstrates how to consume the standard library as a module using the command line compiler. The Visual Studio IDE experience for importing the standard library as a module is still being implemented.
5757

5858
The standard library is imported into your application with the statement `import std;` or `import std.compat;`. But first, you must compile the standard library named modules. The following steps demonstrate how.
5959

@@ -203,17 +203,17 @@ Before you can use `import std.compat;` in your code, you must compile the named
203203
204204
Versioning for named modules is the same as for headers. The `.ixx` named module files live alongside the headers, for example: `"%VCToolsInstallDir%\modules\std.ixx`, which resolves to `C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.35.32019\modules\std.ixx` in the version of the tools used at the time of this writing. Select the version of the named module to use the same way you choose the version of the header file to use--by the directory you refer to them from.
205205
206-
Don't mix and match importing header units and named modules. That is, don't `import <vector>;` and `import std;` in the same file, for example. You'll get a compiler error.
206+
Don't mix and match importing header units and named modules. For example, don't `import <vector>;` and `import std;` in the same file.
207207
208-
Don't mix and match importing header units and name modules. That is, don't `#include <vector>` and `import std;` in the same file, for example.
208+
Don't mix and match importing C++ standard library header files and named modules. For example, don't `#include <vector>` and `import std;` in the same file. However, you can include C headers and import named modules in the same file. For example, you can `import std;` and `#include <math.h>` in the same file. Just don't include the C++ standard library version, `<cmath>`.
209209
210-
You don't have to defend against importing a module multiple times. No header guard `#ifndef` required. The compiler knows when it has already imported a named module and ignores duplicate attempts to do so.
210+
You don't have to defend against importing a module multiple times: no header guard `#ifndef` required. The compiler knows when it has already imported a named module and ignores duplicate attempts to do so.
211211
212212
If you need to use the `assert()` macro, then `#include <assert.h>`.
213213
214-
If you need to use the `errno` macro, `#include <assert.h>`. Because named modules don't expose macros, this is the workaround if you need to check for errors from `<cmath>` functions.
214+
If you need to use the `errno` macro, `#include <errno.h>`. Because named modules don't expose macros, this is the workaround if you need to check for errors from `<math.h>`, for example.
215215
216-
`INT_MIN` is defined by `<limits.h>` and `<climits>` and works with header files/header units. However, those two headers won't work as a named module because named modules don't expose macros. You can use `std::numeric_limits<int>::min()` instead.
216+
Macros such as `NAN`, `INFINITY`, and `INT_MIN` are defined by `<limits.h>`, which you can include. However, if you `import std;` you can use `numeric_limits<double>::quiet_NaN()` and `numeric_limits<double>::infinity()` instead of `NAN` and `INFINITY`, and `std::numeric_limits<int>::min()` instead of `INT_MIN`.
217217
218218
## Summary
219219

0 commit comments

Comments
 (0)