Skip to content

Commit 805b00d

Browse files
Merge pull request #5188 from MicrosoftDocs/main638751546375026527sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 91e2050 + 529d630 commit 805b00d

File tree

5 files changed

+76
-84
lines changed

5 files changed

+76
-84
lines changed

docs/build/reference/experimental-module.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,57 @@
11
---
22
title: "/experimental:module (Enable module support)"
33
description: "Use the /experimental:module compiler option to enable experimental compiler support for named modules."
4-
ms.date: 01/27/2022
4+
ms.date: 02/12/2025
55
f1_keywords: ["module", "/experimental:module"]
66
helpviewer_keywords: ["module", "/experimental:module", "Enable module support"]
77
---
8-
# `/experimental:module` (Enable module support)
8+
# `/experimental:module` (Enable experimental module support)
99

10-
Enables experimental compiler support for C++ Standard modules. This option is obsolete for C++20 standard modules in Visual Studio version 16.11 and later. It's still required (along with [`/std:c++latest`](std-specify-language-standard-version.md)) for the experimental Standard library modules.
10+
Enables compiler support for Microsoft's experimental form of C++ Standard modules. This option is obsolete in Visual Studio 2019 version 16.11 and later.
1111

1212
## Syntax
1313

1414
> **`/experimental:module`**\[**`-`**]
1515
1616
## Remarks
1717

18-
In versions of Visual Studio before Visual Studio 2019 version 16.11, you can enable experimental modules support by use of the **`/experimental:module`** compiler option along with the [`/std:c++latest`](std-specify-language-standard-version.md) option. In Visual Studio 2019 version 16.11, module support is enabled automatically by either **`/std:c++20`** or **`/std:c++latest`**. Use **`/experimental:module-`** to disable module support explicitly.
18+
This switch was for the time before the new, standardized, way of consuming the C++ Standard Library as modules described in [Import the C++ standard library using modules](../../cpp/tutorial-import-stl-named-module.md) was available. Although you can use this switch to use the older experimental named modules, we recommend that you use the new, standardized, way of consuming the C++ Standard Library as modules described in [Import the C++ standard library using modules](../../cpp/tutorial-import-stl-named-module.md).
1919

20-
This option is available starting in Visual Studio 2015 Update 1. As of Visual Studio 2019 version 16.2, C++20 Standard modules aren't fully implemented in the Microsoft C++ compiler. Modules support is feature complete in Visual Studio 2019 version 16.10. You can use the modules feature import the Standard Library modules provided by Microsoft. A module and the code that consumes it must be compiled with the same compiler options.
20+
This compiler became available starting in Visual Studio 2015 Update 1. Ensure that **C++ Modules for v143 build tools (x64/x86 - experimental)** in selected the VS Installer. It's available in the **Individual components** tab of the installer. Search for **experimental** to see the option. For more information, see [Install C and C++ support in Visual Studio](../vscpp-step-0-installation.md).
2121

22-
For more information on modules and how to use and create them, see [Overview of modules in C++](../../cpp/modules-cpp.md).
22+
| Version | Status |
23+
|---|---|
24+
| Visual Studio 2015 Update 1 | `/experimental:module` introduced. |
25+
| Visual Studio 2019 version 16.10 | C++20 modules support is feature complete. |
26+
| Visual Studio 2019 16.11 and earlier | Enable experimental modules support using **`/experimental:module`** along with [`/std:c++latest`](std-specify-language-standard-version.md). |
27+
| Visual Studio 2019 version 16.11 and later | Modules support is enabled automatically with **`/std:c++20`** or later, or **`/std:c++latest`**. Use **`/experimental:module-`** to disable experimental module support. |
28+
29+
The experimental library consists of the following named modules:
30+
31+
- `std.regex` provides the content of header `<regex>`
32+
- `std.filesystem` provides the content of header `<filesystem>`
33+
- `std.memory` provides the content of header `<memory>`
34+
- `std.threading` provides the contents of headers `<atomic>`, `<condition_variable>`, `<future>`, `<mutex>`, `<shared_mutex>`, and `<thread>`
35+
- `std.core` provides everything else in the C++ Standard Library
36+
37+
To consume these modules, add an import declaration to the top of the source code file. For example:
38+
39+
```cpp
40+
import std.core;
41+
import std.regex;
42+
```
43+
44+
To consume the experimental Microsoft Standard Library modules, compile your program with the [`/EHsc`](eh-exception-handling-model.md) and [`/MD`](md-mt-ld-use-run-time-library.md) options.
2345

2446
### To set this compiler option in the Visual Studio development environment
2547

2648
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
27-
2849
1. Set the **Configuration** drop-down to **All Configurations**.
29-
3050
1. Select the **Configuration Properties** > **C/C++** > **Language** property page.
31-
3251
1. Modify the **Enable C++ Modules (experimental)** property, and then choose **OK**.
3352

53+
For more information about how to use and create modules, see [Overview of modules in C++](../../cpp/modules-cpp.md).
54+
3455
## See also
3556

3657
[`/headerUnit` (Use header unit IFC)](headerunit.md)\

docs/cpp/import-export-module.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
title: "module, import, export"
3-
ms.date: 02/14/2022
3+
ms.date: 02/13/2025
44
f1_keywords: ["module_cpp", "import_cpp", "export_cpp"]
55
helpviewer_keywords: ["modules [C++]", "modules [C++], import", "modules [C++], export"]
66
description: Use import and export declarations to access and to publish types and functions defined in the specified module.
77
---
88
# `module`, `import`, `export`
99

10-
The **`module`**, **`import`**, and **`export`** declarations are available in C++20 and require the [`/experimental:module`](../build/reference/experimental-module.md) compiler switch along with [`/std:c++20`](../build/reference/std-specify-language-standard-version.md) or later (such as **`/std:c++latest`**). For more information, see [Overview of modules in C++](modules-cpp.md).
10+
The **`module`**, **`import`**, and **`export`** declarations are available in C++20 and require the compiler switch [`/std:c++20`](../build/reference/std-specify-language-standard-version.md) or later (such as **`/std:c++latest`**). For more information, see [Overview of modules in C++](modules-cpp.md).
1111

1212
## `module`
1313

@@ -19,7 +19,7 @@ module ModuleA;
1919

2020
## `export`
2121

22-
Use an **`export module`** declaration for the module's primary interface file, which must have extension *`.ixx`*:
22+
Use an **`export module`** declaration for the module's primary interface file, which has an extension *`.ixx`* by default. If you want to use a different extension, use the [/interface](../build/reference/interface.md) switch to compile it as a module interface.
2323

2424
```cpp
2525
export module ModuleA;

docs/cpp/modules-cpp.md

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Overview of modules in C++"
3-
ms.date: 01/29/2024
3+
ms.date: 02/11/2025
44
helpviewer_keywords: ["modules [C++]", "modules [C++], overview"]
55
description: Modules in C++20 provide a modern alternative to header files.
66
---
@@ -14,44 +14,15 @@ You can use modules side by side with header files. A C++ source file can `impor
1414

1515
To contrast modules with other ways to import the standard library, see [Compare header units, modules, and precompiled headers](../build/compare-inclusion-methods.md).
1616

17-
## Enable modules in the Microsoft C++ compiler
17+
Starting with Visual Studio 2022 version 17.5, importing the Standard Library as a module is both standardized and fully implemented in the Microsoft C++ compiler. To learn how to import the Standard Library using modules, see [Import the C++ standard library using modules](tutorial-import-stl-named-module.md).
1818

19-
As of Visual Studio 2022 version 17.1, C++20 standard modules are fully implemented in the Microsoft C++ compiler.
19+
## Single-partition modules
2020

21-
Before it was specified by the C++20 standard, Microsoft had experimental support for modules. The compiler also supported importing prebuilt Standard Library modules, described below.
21+
A single-partition module is a module that consists of a single source file. The module interface and implementation are in the same file.
2222

23-
Starting with Visual Studio 2022 version 17.5, importing the Standard Library as a module is both standardized and fully implemented in the Microsoft C++ compiler. This section describes the older, experimental method, which is still supported. For information about the new standardized way to import the Standard Library using modules, see [Import the C++ standard library using modules](tutorial-import-stl-named-module.md).
23+
The following single-partition module example shows a simple module definition in a source file called *`Example.ixx`*. The *`.ixx`* extension is the default extension for module interface files in Visual Studio. If you want to use a different extension, use the [/interface](../build/reference/interface.md) switch to compile it as a module interface. In this example, the interface file contains both the function definition and the declaration. You can also place the definitions in one or more separate module implementation files, as shown in a later example, but this is an example of a single-partition module.
2424

25-
You can use the modules feature to create single-partition modules and to import the Standard Library modules provided by Microsoft. To enable support for Standard Library modules, compile with [`/experimental:module`](../build/reference/experimental-module.md) and [`/std:c++latest`](../build/reference/std-specify-language-standard-version.md). In a Visual Studio project, right-click the project node in **Solution Explorer** and choose **Properties**. Set the **Configuration** drop-down to **All Configurations**, then choose **Configuration Properties** > **C/C++** > **Language** > **Enable C++ Modules (experimental)**.
26-
27-
A module and the code that consumes it must be compiled with the same compiler options.
28-
29-
## Consume C++ Standard Library as modules (experimental)
30-
31-
This section describes the experimental implementation, which is still supported. The new standardized way of consuming the C++ Standard Library as modules is described in [Import the C++ standard library using modules](tutorial-import-stl-named-module.md).
32-
33-
By importing the C++ Standard Library as modules rather than including it through header files, you can potentially speed up compilation times depending on the size of your project. The experimental library is split into the following named modules:
34-
35-
- `std.regex` provides the content of header `<regex>`
36-
- `std.filesystem` provides the content of header `<filesystem>`
37-
- `std.memory` provides the content of header `<memory>`
38-
- `std.threading` provides the contents of headers `<atomic>`, `<condition_variable>`, `<future>`, `<mutex>`, `<shared_mutex>`, and `<thread>`
39-
- `std.core` provides everything else in the C++ Standard Library
40-
41-
To consume these modules, add an import declaration to the top of the source code file. For example:
42-
43-
```cpp
44-
import std.core;
45-
import std.regex;
46-
```
47-
48-
To consume the Microsoft Standard Library modules, compile your program with the [`/EHsc`](../build/reference/eh-exception-handling-model.md) and [`/MD`](../build/reference/md-mt-ld-use-run-time-library.md) options.
49-
50-
## Example
51-
52-
The following example shows a simple module definition in a source file called *`Example.ixx`*. The *`.ixx`* extension is required for module interface files in Visual Studio. In this example, the interface file contains both the function definition and the declaration. However, you can also place the definitions in one or more separate module implementation files, as shown in a later example.
53-
54-
The `export module Example;` statement indicates that this file is the primary interface for a module called `Example`. The **`export`** modifier on `f()` indicates that this function is visible when another program or module imports `Example`.
25+
The `export module Example;` statement indicates that this file is the primary interface for a module called `Example`. The **`export`** modifier before `int f()` indicates that this function is visible when another program or module imports `Example`:
5526

5627
```cpp
5728
// Example.ixx
@@ -61,12 +32,14 @@ export module Example;
6132

6233
namespace Example_NS
6334
{
64-
int f_internal() {
65-
return ANSWER;
66-
}
35+
int f_internal()
36+
{
37+
return ANSWER;
38+
}
6739

68-
export int f() {
69-
return f_internal();
40+
export int f()
41+
{
42+
return f_internal();
7043
}
7144
}
7245
```
@@ -88,7 +61,7 @@ int main()
8861
}
8962
```
9063

91-
The `import` declaration can appear only at global scope.
64+
The `import` declaration can appear only at global scope. A module and the code that consumes it must be compiled with the same compiler options.
9265

9366
## Module grammar
9467

@@ -138,6 +111,7 @@ When the compiler does argument-dependent lookup for overload resolutions in the
138111
### Module partitions
139112

140113
A module partition is similar to a module, except:
114+
141115
- It shares ownership of all declarations in the entire module.
142116
- All names exported by partition interface files are imported and exported by the primary interface file.
143117
- A partition's name must begin with the module name followed by a colon (`:`).

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This tutorial requires Visual Studio 2022 17.5 or later.
2424

2525
## Introduction to standard library modules
2626

27-
Header files suffer from semantics that can change depending on macro definitions, the order in which you include them, and they slow compilation. Modules solve these problems.
27+
Header file semantics can change depending on macro definitions, the order in which you include them, and they slow compilation. Modules solve these problems.
2828

2929
It's now possible to import the standard library as a module instead of as a tangle of header files. This is much faster and more robust than including header files or header units or precompiled headers (PCH).
3030

@@ -39,14 +39,12 @@ Because named modules don't expose macros, macros like `assert`, `errno`, `offse
3939

4040
## About C++ modules
4141

42-
Header files are how declarations and definitions have been shared between source files in C++. Prior to standard library modules, you'd include the part of the standard library you needed with a directive like `#include <vector>`. Header files are fragile and difficult to compose because their semantics may change depending on the order you include them, or whether certain macros are defined. They also slow compilation because they're reprocessed by every source file that includes them.
42+
Header files are how declarations and definitions have been shared between source files in C++. Before standard library modules, you'd include the part of the standard library you needed with a directive like `#include <vector>`. Header files are fragile and difficult to compose because their semantics may change depending on the order you include them, or whether certain macros are defined. They also slow compilation because they're reprocessed by every source file that includes them.
4343

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

4646
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 much faster than it can process `#include` files, and uses less memory at compile time as well. Named modules don't expose macro definitions or private implementation details.
4747

48-
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.
49-
5048
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).
5149

5250
## Import the standard library with `std`
@@ -57,7 +55,7 @@ The statement `import std;` or `import std.compat;` imports the standard library
5755

5856
### Example: How to build and import `std`
5957

60-
1. Open a x86 Native Tools Command Prompt for VS: from the Windows **Start** menu, type *x86 native* and the prompt should appear in the list of apps. Ensure that the prompt is for Visual Studio 2022 version 17.5 or above. You'll get errors if you use the wrong version of the prompt. The examples used in this tutorial are for the CMD shell.
58+
1. Open a x86 Native Tools Command Prompt for VS: from the Windows **Start** menu, type *x86 native* and the prompt should appear in the list of apps. Ensure that the prompt is for Visual Studio 2022 version 17.5 or above. You get errors if you use the wrong version of the prompt. The examples used in this tutorial are for the CMD shell.
6159
1. Create a directory, such as `%USERPROFILE%\source\repos\STLModules`, and make it the current directory. If you choose a directory that you don't have write access to, you'll get errors during compilation.
6260
1. Compile the `std` named module with the following command:
6361

0 commit comments

Comments
 (0)