Content deleted Content added
m Open access bot: arxiv updated in citation with #oabot. |
No edit summary Tags: Mobile edit Mobile app edit iOS app edit App section source |
||
Line 543:
The C++ standard library remains accessible through headers, however since C++23 it has been made accessible using modules as well.<ref name=cppreferencemodules /><ref name=cppreferencestandardlibrary /> Even with the introduction of modules, headers continue to play a role in modern C++, as existing codebases have not completely migrated to modules.
==== Header units ====
Headers are traditionally included via textual inclusion by the preprocessor using <code>#include</code>, while modules are included during compilation through <code>import</code>. However, headers may also be imported using <code>import</code>, even if they are not declared as modules – these are called "header units", and they are designed to allow existing codebases to migrate from headers to modules more gradually.<ref>{{cite web|url=https://learn.microsoft.com/en-us/cpp/build/walkthrough-header-units?view=msvc-170|title=Walkthrough: Build and import header units in Microsoft Visual C++|date=12 April 2022 |publisher=Microsoft}}</ref> The syntax is similar to including a header, with the difference being that <code>#include</code> is replaced with <code>import</code> and a semicolon is placed at the end of the statement. Header units automatically export all symbols, and differ from proper modules in that they allow the emittance of macros, meaning all who import the header unit will obtain its contained macros. This offers minimal breakage between migration to modules. The semantics of searching for the file depending on whether quotation marks or angle brackets are used apply here as well. For instance, one may write <syntaxhighlight lang="C++" inline>import <string>;</syntaxhighlight> to import the <code><string></code> header, or <syntaxhighlight lang="C++" inline>import "MyHeader.h";</syntaxhighlight> to import the file <code>"MyHeader.h"</code> as a header unit. Most build systems, such as [[CMake]], do not support this feature yet.
=== Modules ===
|