麻药叫什么名字| 声音沙哑是什么原因| 宝宝咳嗽吃什么药| 勃艮第红是什么颜色| 晚上睡觉腿抽筋是什么原因| 纠结是什么意思| 下身灼热感什么原因| 铜锣湾有什么好玩的| 电影下映是什么意思| 铁扇公主是什么妖精| 一丝不苟是什么生肖| 杰五行属什么| 红斑狼疮的症状是什么| 暗网是什么意思| 小孩睡觉出很多汗是什么原因| 天秤座女生什么性格| 艾灰有什么作用和功效| 头晕可以吃什么药| 有志什么成| 物以类聚是什么意思| 三八妇女节是什么生肖| 尿点什么意思| 复杂性囊肿是什么意思| 为什么会得阑尾炎| 文艺范是什么意思| 喜面是什么意思| 慢性荨麻疹吃什么药| 月经前一周失眠是什么原因| 血小板高是什么意思| 一个人是什么歌| 御守是什么意思| 坎宅是什么意思| 小孩补钙吃什么最好| 高血压吃什么药好| 痛风检查什么项目| 氯化镁是什么| dostinex是什么药| 中性粒细胞高是什么原因| 硬伤是什么意思| 什么那是什么吧| 男生什么情况想种草莓| 爸爸的外婆叫什么| 多发纳氏囊肿是什么意思| 刷牙时牙龈出血是什么原因| 窝里横是什么意思| 冷泡茶用什么茶叶| 同房肚子痛是什么原因| 嫖娼是什么意思| 跳闸是什么原因| 秋天是什么时候| 脚底长水泡是什么原因| 新生婴儿吃什么奶粉| 百脚虫的出现意味什么| 东南方是什么生肖| 胃不消化吃什么药| 梅花象征着什么| 暗娼什么意思| 48年属什么| 氨纶是什么| 照烧是什么意思| 母亲过生日送什么礼物| hbcab偏高是什么意思| 何德何能是什么意思| 夜来香是什么花| 胃酸过多有什么症状| 脑梗能吃什么| 急性胃炎吃什么药好| 知了长什么样| 耳鸣什么原因引起的| 手指头脱皮是什么原因| 什么嫩芽| 疲软是什么意思| 11月出生是什么星座| 香榧是什么| 人间仙境是什么意思| 说什么道什么| 热疖痈毒是什么意思| 68年属猴的是什么命| 办理港澳通行证需要带什么证件| 人为什么不可以偏食| 刮痧是什么原理| 无极是什么意思| 海带是什么植物| 木驴是什么| 花旦是什么意思| 眼球出血是什么原因引起的| 四维空间是什么| 二尖瓣反流吃什么药| 什么是假药| covu是什么药| 耳朵尖的人什么命| 梵高属于什么画派| 嫩模是什么意思| 辣条吃多了有什么危害| 3岁小孩说话结巴是什么原因| 脾虚要吃什么东西调理| 羽加立念什么| 虾子不能和什么一起吃| jessica是什么意思| 理性什么意思| 肠胃炎挂什么科| 摸头杀是什么意思| 包皮手术后吃什么伤口愈合快| 梨的功效与作用是什么| 土地确权是什么意思| 脾胃虚寒吃什么药好| 鱼头炖什么好吃| 吃什么对心脏好| 甲状腺三项检查什么| 阑尾炎可以吃什么水果| 痛经什么原因引起的| 藕是莲的什么部位| 贯众是什么植物| 尿尿疼是什么原因| dj管是什么| 43岁属什么生肖| 肠梗阻是什么症状| 改编是什么意思| 晚安安是什么意思| 属狗的和什么属相最配| 什么可以代替狗狗沐浴露| 什么中药能降血压| 吃什么对头发有好处| 安可什么意思| 5.2号是什么星座| 缺维生素d有什么症状| 警察在古代叫什么| 邋遢是什么意思| 鹿晗什么时候回国的| 腋下是什么部位| 扎手指放血治什么| 肝胆相照是什么意思| 必修课是什么意思| 绿本是什么| 朱元璋是什么朝代| 6月5日是什么日子| 花甲不能和什么一起吃| 做梦梦到钓鱼是什么意思| 什么叫红肉| 三个牛读什么字| 辟谣是什么意思| 四肢发麻是什么原因| 调理是什么意思| 粳米是什么米| 清奇是什么意思| 姑姑的孙子叫我什么| 心脏不好吃什么水果好| 甲状腺查什么| 状元是什么意思| 27属相是什么生肖| 浛是什么意思| 婴儿拉肚子是什么原因造成的| 什么是私人会所| 出现幻觉是什么原因引起的| 求购是什么意思| 姜枣茶什么季节喝最好| 胸疼是什么原因| 九月二十八是什么星座| 龙骨是什么动物的骨头| 空调输入功率是什么意思| 此地无银三百两什么意思| 脚掌麻木是什么原因| 积液是什么东西| zzy是什么意思| 去湿气吃什么药| 维生素c主治什么| rhino是什么意思| 什么食粮| 什么的蜡烛| 什么头什么向| 香港商务签证需要什么条件| 护理部是干什么的| 男女更年期分别在什么年龄| 脖子长痘痘是什么原因| 筠字五行属什么| 世上谁嫌男人丑的前一句是什么| 老烂腿用什么药最好| 刘字五行属什么| 马蜂蛰了用什么药| 什么是毛囊炎| 1959年是什么年| 94年属什么生肖| 六堡茶是什么茶| 粉尘螨是什么东西| 剖腹产后能吃什么水果| 梦见烧衣服什么预兆| 肠炎吃什么药好| 春饼卷什么菜好吃| 家里蟑螂多是什么原因| 安痛定又叫什么| 斗鱼吃什么| ca199是什么意思| 不复相见什么意思| 人体出汗多是什么原因| 吃什么长卵泡| pussy是什么意思| 经常中暑的人体内缺什么| 花甲是什么| 体内湿热吃什么中成药| 脚痛是什么原因| 腿脚酸软无力是什么原因| 宝路华手表什么档次| 场所是什么意思| 鲜花又什么又什么| 全身皮肤瘙痒是什么原因引起的| 虔婆是什么意思| 前列腺炎用什么药| 孕妇梦见坟墓是什么预兆| 什么是等位基因| 痔疮用什么药膏最好| 曹丕为什么不杀曹植| 密度灶是什么意思| 山代表什么动物| 巽是什么意思| 喝黑枸杞有什么作用和功效| 喵喵喵是什么意思| 三金片有什么副作用| bra是什么| 高攀是什么意思| 口水臭什么原因| 谷草谷丙偏高是什么意思| 补肾虚吃什么药最好| 喝莓茶有什么好处| 71年属猪是什么命| 脑萎缩挂什么科| boy是什么品牌| 智齿是什么| 什么医院才是正规医院| 什么情况下吃奥司他韦| 头热是什么原因| 为什么鞋子洗了还是臭| emoji什么意思| 朝阳是什么意思| 天是什么生肖| 夫妻都是a型血孩子是什么血型| 梦代表什么生肖| 睡觉口干舌燥什么原因| 吃什么补白蛋白最快最好| 肺泡是什么| camp是什么| 天空中有什么| 胆固醇是什么意思| 脖子黑是什么原因| 蚊虫叮咬擦什么药膏| 滑膜炎是什么病| 绝对值是什么| 维生素d是什么| 垂死病中惊坐起什么意思| 什么茶叶能减肥刮油脂肪| 苹果浓缩汁是什么| april是什么意思| 缄默症是什么病| 拔罐有什么作用和功效| 2006属什么| 为什么白天能看到月亮| 睡美人最怕什么| 柚子什么时候成熟| 六月十六是什么星座| 睡觉打嗝是什么原因| 什么叫脑白质病| 三有动物是什么意思| 产前诊断是检查什么| 二尖瓣少量反流是什么意思| 缩量十字星意味着什么| 百度Jump to content

365淘房手机版(手机365淘房安卓版下载)V6.4.20官方版

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 24.50.56.74 (talk) at 23:47, 28 July 2025 (Add history section and more citations.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
  • Comment: (In response) I have reworded many parts of the article to be less essay-like and added official ISO C++ specification citations wherever applicable, I think it is adequately sourced now. 24.50.56.74 (talk) 23:17, 24 July 2025 (UTC)
  • Comment: Some large sections of unsourced text. Encoded  Talk ?? 22:01, 26 June 2025 (UTC)

百度 惊蛰一过,春耕始忙。

Modules in C++ are a feature added in C++20 implementing modular programming as a modern alternative to precompiled headers.[1] A module in C++ comprises a single translation unit.[2] Like header files and implementation files, a module can contain declarations and definitions, but differ from precompiled headers in that they do not require the preprocessor directive #include, but rather are accessed using the word import. A module must be declared using the word module to indicate that the translation unit is a module.[1] A module, once compiled, is stored as a .pcm (precompiled module) file which acts very similar to a .pch (precompiled header) file.[3]

Modules most commonly have the extension .cppm (primarily common within Clang and GCC toolchains), though some alternative extensions include .ixx and .mxx (more common in Microsoft/MSVC toolchains).[4]

Though the standard C language does not have modules, dialects of C allow for modules, such as Clang C.[5] However, the syntax and semantics of Clang C modules differ from C++ modules significantly.

History

Prior to the conception of modules, C++ relied on the system of headers and source files. Precompiled headers existed and were similar to modules as snapshots of translation units easier to parse by the compiler and thus providing faster compilation[6], but did not have the same laws of encapsulation as modules. Modules were first proposed in 2012 for inclusion to C++14[7], but underwent extensive revisions and an entire redesign until the modern form was merged into C++20.[8]

Main uses

Modules provide the benefits of precompiled headers of faster compilation than #included traditional headers, as well as and faster processing during the linking phase.[9][10] This is because modules are not handled by the C preprocessor during the preprocessing step, but rather directly by the compiler during compilation.[11] Modules also reduce boilerplate by allowing code to be implemented in a single file, rather than being separated across a header file and source implementation, although separation of "interface file" and "implementation file" is still possible with modules, though modules provide a cleaner encapsulation of code.[2] Modules eliminate the necessity of #include guards or #pragma once, as modules do not directly modify the source code. Modules, unlike headers, do not have to be processed or recompiled multiple times.[9] However, similar to headers, any change in a module necessitates the recompilation of not only the module itself but also all its dependencies, and the dependencies of those dependencies, et cetera. Like headers, modules do not permit circular dependencies, and will not compile.[12]

A module is imported using the keyword import followed by a module name[a], while a module is declared with export module followed by the name. All symbols within a module meant to be exposed publicly are marked export, and importing the module exposes all exported symbols to the translation unit. If a module is never imported, it will never be linked.[13] Modules can export named symbols, but not macros which are consumed before compilation.[14]

Unlike header inclusions, the order of import statements do not matter.[9] A module can allow for transitive imports by marking an import with export import, which re-exports the imported module to a translation unit that imports the first module.[1] Modules do not enforce any notion of namespaces, but it is not uncommon to see projects manually associate modules to namespaces (for example, a namespace like exampleproj::util::contents being tied to the module exampleproj.util.contents).[1] using statements will only be applied in translation units if explicitly marked export, making it much less likely that using a using statement to bring symbols into the global namespace will cause name clashes across module translation units.

Currently, only GCC, Clang, and MSVC offer support for modules.[15]

Standard library modules

Since C++23, the C++ standard library has been exported as a module as well, though as of currently it must be imported in its entirety (using import std;).[16] The C++ standards offer two standard library modules:

Name Description
std Exports all declarations in namespace std and global storage allocation and deallocation functions that are provided by the importable C++ library headers including C library facilities (although declared in standard namespace).
std.compat Exports the same declarations as the named module std, and additionally exports functions in global namespace in C library facilities. It thus contains "compat" in the name, meaning compatibility with C.

The module names std and std.* are reserved by the C++ standard, and thus declaring a module whose name matches either pattern will issue a compiler warning.[17] However, most compilers provide a flag to bypass or suppress that warning (for example -Wno-reserved-module-identifier in Clang and GCC).[3]

Currently, only GCC, Clang, and MSVC support standard library modules.[18]

Example

A simple example of using modules is as follows:

MyClass.cppm

export module myproject.MyClass;

import std;

export namespace myproject {

class MyClass {
private:
    int x;
    std::string name;
public:
    MyClass(int x, const std::string& name):
        x{x}, name{name} {}

    [[nodiscard]]
    int getX() const noexcept {
        return x;
    }

    void setX(int newX) noexcept {
        x = newX;
    };

    [[nodiscard]]
    std::string getName() const noexcept {
        return name;
    }

    void setName(const std::string& newName) noexcept {
        name = newName;
    }
};

}

Main.cpp

import std;

import myproject.MyClass;

using myproject::MyClass;

int main(int argc, char* argv[]) {
    MyClass me(10, "MyName");
    me.setX(15);
    std::println("Hello, {0}! {0} contains value {1}.", me.getName(), me.getX());
}

Header units

Headers may also be imported using import, even if they are not declared as modules. Imported headers are called "header units", and are designed to allow existing codebases to migrate from headers to modules more gradually.[19][20] The syntax is similar to including a header, with the difference being that #include is replaced with import. As import statements are not preprocessor directives but rather statements of the language read by the compiler[11], they must be terminated by a semicolon. Header units automatically export all symbols, and differ from proper modules in that they allow the emittance of macros, meaning all translation units that import the header unit will obtain its contained macros. This offers minimal breakage between migration to modules.[9] 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 import <string>; to import the <string> header, or import "MyHeader.h"; to import the file "MyHeader.h" as a header unit.[1] Most build systems, such as CMake, do not support this feature yet.[21]

Anatomy

Module partitions and hierarchy

Modules may have partitions, which separate the implementation of the module across several files.[1] Module partitions are declared using the syntax A:B, meaning the module A has the partition B. Module partitions cannot individually be imported outside of the module that owns the partition itself, meaning that any translation unit that requires code located in a module partition must import the entire module that owns the partition.[1]

The module partition B is linked back to the owning module A with the statement import :B; in the file containing the declaration of module A or any other module partition of A (say A:C), which implicitly resolves :B to A:B, because the module is named A.[3] These import statements may themselves be exported by the owning module, even if the partition itself cannot be imported directly, and thus importing code from a partition is done by just importing the entire module.[1]

Other than partitions, modules do not have a hierarchical system or "submodules", but typically use a hierarchical naming convention, similar to Java's packages[b]. Only alphanumeric characters and the period and underscore may appear in the name of a module.[22] In C++, the name of a module is not tied to the name of its file or the module's location, unlike in Java[23], and the package it belongs to must match the path it is located in.[24] For example, the modules A and A.B in theory are disjoint modules and need not necessarily have any relation, however such a naming scheme is often employed to suggest that the module A.B is related or otherwise associated with the module A.[1]

The naming scheme of a C++ module is inherently hierarchical, and the C++ standard recommends re-exporting "sub-modules" belonging to the same public API (i.e. module alpha.beta.gamma should be re-exported by alpha.beta, etc.), even though dots in module names do not enforce any hierarchy. The C++ standard recommends lower-case ASCII module names (without hyphens or underscores), even though there is technically no restriction in such names.[25] Also, because modules cannot be re-aliased or renamed (short of re-exporting all symbols in another module), module names can be prefixed with organisation/project names for both clarity and to prevent naming clashes (i.e. google.abseil instead of abseil).[25] Also, unlike Java, whose packages may typically include a TLD to avoid namespace clashes, C++ modules need not have this convention.

Module purview and global module fragment

In the above example, everything above the line export module myproject.MyClass; in the file MyClass.cppm is referred to as what is "outside the module purview", meaning what is outside of the scope of the module.[1] Typically, all #includes are placed outside the module purview between the statement module; and the declaration of export module, like so:

module; // Optional; marks the beginning of the global module fragment (mandatory if an include directive is invoked above the export module declaration)

// Headers are included in outside the module purview, before the module is declared
#include <print>
#include "MyHeader.h"

export module myproject.MyModule; // Mandatory; marks the beginning of the module preamble

// Imports of named modules and header units come after the module declaration
// Import statements are placed immediately after the module declaration and do not appear after any code or symbol declarations
// In non-module translation units, #include directives precede import statements
import std;
import <string>;
import myproject.util.UtilitySymbols;
import "Foo.h";
import <thirdlib/features/Feature.h>;

// Code here...

module: private; // Optional; marks the beginning of the private module fragment

All code which does not belong to any module exists in the so-called "unnamed module" (also known as the global module fragment), and thus cannot be imported by any module.[1]

The file containing main() may declare a module, but typically it does not (as it is unusual to export main() as it is typically only used as an entry point to the program, and thus the file is usually a .cpp file and not a .cppm file). A program is ill-formed if it exports main() and doing so causes undefined behaviour[26], but will not necessarily be rejected by the compiler.

Private module fragment

A module may declare a "private module fragment" by writing module: private;, in which all declarations or definitions after the line are visible only from within the file and cannot be accessed by translation units that import that module.[3] Any module unit that contains a private module fragment must be the only module unit of its module.[1]

See also

Notes

  1. ^ The import keyword in C++ differs in meaning than other languages. For instance, import in Java is actually analogous to using in C++ and not C++ import. In the former, an import simply aliases the type or de-qualifies a namespace, because Java loads .class files dynamically as necessary, thus making all types available simply by fully qualifying all namespaces (rather than having to explicitly declare accessible modules). However, in C++ modules are not automatically all linked, and thus they must be manually "imported" to be made accessible, as import indicates that the translation unit must access code in the imported module. Thus, it is probably more appropriate to compare import in C++ to mod in Rust, which "declares" or indicates to the compiler to find the module to link against.
  2. ^ It is more appropriate to compare packages in Java and modules in C++, rather than modules in Java and modules in C++. Modules in C++ and Java differ in meaning. In Java, a module (which is handled by the Java Platform Module System) is used to group several packages together, while in C++ a module is a translation unit, strictly speaking.

References

  1. ^ a b c d e f g h i j k l cppreference.com (2025). "Modules (since C++20)". cppreference.com. Retrieved 2025-08-05.
  2. ^ a b Szalay, R. and Porkoláb, Z. (2025). "Refactoring to Standard C++20 Modules". Journal of Software: Evolution and Process. 37 (e2736). doi:10.1002/smr.2736. Retrieved 2025-08-05.{{cite journal}}: CS1 maint: multiple names: authors list (link)
  3. ^ a b c d "Standard C++ Modules". clang.llvm.org.
  4. ^ "Overview of modules in C++". Microsoft. 24 April 2023.
  5. ^ "Modules". clang.llvm.org.
  6. ^ "Creating Precompiled Header Files". MSDN. Microsoft. 2015. Archived from the original on 2025-08-05. Retrieved 2025-08-05.
  7. ^ Daveed Vandevoorde (2025-08-05). "N3347=12-0037: Modules in C++ (Revision 6)" (PDF). ISO/IEC JTC1/SC22/WG21. Retrieved 2025-08-05.{{cite web}}: CS1 maint: date and year (link)
  8. ^ Richard Smith (2025-08-05). "P1103R3: Merging Modules" (PDF). ISO/IEC JTC1/SC22/WG21. Retrieved 2025-08-05.{{cite web}}: CS1 maint: date and year (link)
  9. ^ a b c d "Compare header units, modules, and precompiled headers". Microsoft. 12 February 2022.
  10. ^ Paul Krill (2 June 2022). "C++ 23 to introduce module support". InfoWorld.
  11. ^ a b Michael Spencer (2025-08-05). "P3034R1: Module Declarations Shouldn't be Macros". ISO/IEC JTC1/SC22/WG21. Retrieved 2025-08-05.{{cite web}}: CS1 maint: date and year (link)
  12. ^ ISO/IEC 14882:2020. Programming Languages – C++ (3rd ed.). International Organization for Standardization. §9.3, "Module interface units and import/export rules," and §16.3, "Module dependencies."
  13. ^ ISO/IEC 14882:2020. Programming Languages – C++ (3rd ed.). International Organization for Standardization. §9.3, "Module interface units and import/export rules," and §16.2, "Module import semantics."
  14. ^ Alisdair Meredith (2025-08-05). "DxxxxR0: Modules and Macros". ISO C++. Retrieved 2025-08-05.{{cite web}}: CS1 maint: date and year (link)
  15. ^ "Compiler support for C++20". cppreference.com.
  16. ^ "Standard library - Importing modules". cppreference.com.
  17. ^ cppreference.com (2025). "C++ Standard Library". cppreference.com. Retrieved 2025-08-05.
  18. ^ "Compiler support for C++23". cppreference.com.
  19. ^ "Walkthrough: Build and import header units in Microsoft Visual C++". Microsoft. 12 April 2022.
  20. ^ "Standard C++ Modules - Header Units". clang.llvm.org.
  21. ^ CppNow (2025-08-05). The Challenges of Implementing C++ Header Units: C++ Modules - Daniel Ruoso - CppNow 2023. YouTube. Retrieved 2025-08-05.
  22. ^ ISO/IEC 14882:2020. Programming Languages – C++ (3rd ed.). International Organization for Standardization. §9.2, "Module interface units and import/export rules."
  23. ^ "Creating a Package". docs.oracle.com.
  24. ^ "Managing Source and Class Files". docs.oracle.com.
  25. ^ a b "Naming guidelines for modules". isocpp.org.
  26. ^ ISO/IEC 14882:2020. Programming Languages – C++ (3rd ed.). International Organization for Standardization. §3.6.1. "Program execution: the main() function."
紫外线过敏用什么药 从政是什么意思 皮肤晒伤用什么药 为什么白带是黄色的 夜尿频多是什么原因
半夜吃东西有什么危害 外阴瘙痒用什么药膏擦 什么是老公 扁桃体化脓是什么原因引起的 做阴超有黄体说明什么
2222是什么意思 消炎吃什么药 山川是什么意思 孕妇血压低吃什么能补上来 真言是什么意思
做三明治需要什么材料 ivy是什么意思 跳蚤咬了擦什么药最好 老年人出虚汗是什么原因引起的 对方忙线中什么意思
什么而起hkuteam.com 金陵十三钗是什么意思hcv8jop7ns1r.cn 多囊卵巢是什么意思hcv9jop0ns2r.cn 转氨酶高是什么tiangongnft.com 青蒿素是什么hcv8jop8ns2r.cn
周围神经病是什么意思bjhyzcsm.com 打嗝挂什么科sanhestory.com cdc什么意思hcv9jop6ns4r.cn 什么是扁桃体hcv8jop8ns7r.cn 突然尿多是什么原因hcv9jop2ns8r.cn
梦见自己扫地是什么意思xjhesheng.com 58岁属什么生肖hcv8jop2ns2r.cn 轩字属于五行属什么hcv7jop7ns3r.cn 伤口结痂为什么会痒hcv9jop6ns9r.cn 霜降吃什么hcv8jop0ns2r.cn
五月十一是什么星座hcv8jop5ns5r.cn 别开生面是什么意思hcv8jop3ns2r.cn 石榴木是什么生肖hcv7jop9ns0r.cn 凌字五行属什么sanhestory.com 家里什么东西止血最快onlinewuye.com
百度