女同是什么意思| 下半年有什么节日| pickup是什么意思| 官方旗舰店和旗舰店有什么区别| ns什么意思| 喝豆浆有什么好处| 牙齿经常出血是什么原因| 热症是什么意思| 洛什么意思| 胃肠化是什么意思| 舌头上有黑点是什么原因| 要不然是什么意思| 横财是什么意思| 起水泡痒是什么原因| 景色什么| 验孕棒什么时候测最准确| 黄鼠狼为什么怕鹅| 头疼流鼻血是什么原因| 灰菜有什么功效与作用| 白垩纪是什么意思| 早上11点是什么时辰| 铅中毒用什么解毒| 香蕉为什么是弯的| 妇科臭氧治疗的作用是什么| pet一ct是一种什么检查| ex是什么意思| 腔梗是什么意思| 梦见塌方是什么预兆| qid医学上是什么意思| 心率早搏是什么意思| camper是什么牌子| 感冒拉肚子吃什么药| 猴魁属于什么茶| 脚心发热吃什么药| cc是什么意思啊| 肺炎吃什么药最有效| 汪峰什么星座| ccu是什么| 黄粱是什么意思| 爱情是什么颜色的| 男人小便刺痛吃什么药| 望闻问切的闻是什么意思| 什么虫咬了起水泡| 艳羡是什么意思| 复合是什么意思| 儿童流鼻涕吃什么药| 鼻炎吃什么药效果最好| 宿便是什么意思| nothomme什么牌子| 晨起口干口苦是什么原因| 字号是什么意思| 左眼皮跳什么意思| 寻常疣是什么样子图片| 霉菌性阴道炎是什么原因引起的| pnp是什么意思| 梦见莲藕是什么意思| 气管疼什么原因引起的| 梦见黑蛇是什么预兆| 唐玄宗为什么叫唐明皇| 念珠菌和霉菌有什么区别| 什么水不能喝| 见利忘义是什么意思| 刚怀孕初期吃什么好呢| 御姐范是什么意思| 大熊猫是什么科| 遗精频繁是什么原因| bu什么颜色| 糖醋里脊是什么肉做的| 夏枯草长什么样| 过敏吃什么| 情感障碍是什么| 植物神经紊乱吃什么药| 什么南什么北| 小狗什么时候断奶| 女人为什么会来月经| 什么品牌的冰箱好| 牙龈发紫是什么原因| 凯格尔运动是什么| 做什么梦暗示你怀孕了| 眼角膜脱落有什么症状| 这是什么呀| 87年是什么年| 小苏打是什么| 徒刑是什么意思| 上颌窦炎症是什么病| 闺蜜是什么样的关系| ldpe是什么材料| 放荡不羁爱自由什么意思| 虎是什么结构| 什么叫道德绑架| 槿字五行属什么| 洁面慕斯和洗面奶有什么区别| 陈皮和什么泡水喝最好| 梦到亲人死了是什么征兆| 什么是碱性食物有哪些| 拔了尿管尿不出来有什么好办法| 拉黑色大便是什么原因| 什么水果含糖低| 吃完饭就想睡觉是什么原因| 咖喱是什么做的| 婴儿大便隐血阳性是什么意思| 皮试是什么| 上四休二是什么意思| 三焦湿热吃什么中成药| 102是什么意思| 梦到自己头发白了是什么意思| 脱髓鞘是什么病| 大保健是什么| 男人吃什么壮阳最快| 劳碌命是什么意思| 婴儿补铁吃什么铁剂| 长痘痘吃什么水果好| 小苏打和食用碱有什么区别| 总放屁是什么原因| 大便有粘液是什么原因| 谷氨酸高是什么原因| 主治医师是什么级别| 头晃动是什么病的前兆| 什么生| 半夜胎动频繁是什么原因| 发生火灾时的正确做法是什么| 检查头部挂什么科室| 舌头上火是什么原因| 啊什么| 炎黄子孙是什么生肖| 口牙是什么意思| 球蛋白的功效与作用是什么| 新疆有什么水果| 吃什么开胃增加食欲| 地蛋是什么| 沫沫是什么意思| 梅开二度是什么意思| 睑腺炎是什么原因造成| 试纸一深一浅说明什么| 打完疫苗不能吃什么| 世界八大奇迹是什么| 藕粉色是什么颜色| 脚踝肿挂什么科| 黄瓜敷脸有什么好处| 2028年是什么年| 口腔扁平苔藓是什么原因造成的| 79属什么生肖| 夕阳西下是什么意思| 大便黑色是什么原因| 臻的意思是什么| 瘦的人吃什么才能变胖| 2月15是什么星座| 什么是spa| 蓝色和红色混合是什么颜色| 蜜蜂糖冲开水有什么好处| 懵的意思是什么| 没有了晨勃是什么原因| 疮疖是什么意思| 坐怀不乱柳下惠什么意思| 善什么甘什么| 什么是可转债| 走马观花的走什么意思| 范思哲手表什么档次| 盐城有什么特产| queen是什么意思| 银色五行属什么| 蝉吃什么食物| 红枣和灰枣有什么区别| 爬山有什么好处| 五十岁是什么之年| 阴道干涩吃什么药| 沙僧的武器叫什么名字| 什么越来越什么什么越来越什么| 幽门螺旋杆菌感染吃什么药| 什么是囊肿| 吃石斛有什么功效| 孕妇梦见捡鸡蛋是什么意思| 什么是碳水食物有哪些| 老虔婆是什么意思| 为什么总是做梦| 手指关节痛吃什么药好| 一岁宝宝吃什么| 新生儿晚上哭闹不睡觉是什么原因| 属鼠的和什么属相相克| 大便秘结是什么原因| 嘴唇肿起来一般是什么原因引起的| 打喷嚏漏尿是什么原因| 什么叫腔梗| hcv阳性是什么意思| 盗汗是什么原因| 滇是什么意思| 胃疼有什么办法缓解| 贫血什么意思| 什么的公鸡| 青是什么颜色| 尘字五行属什么| 气阴两虚吃什么药| 11月14号是什么星座| 回民为什么不吃猪| 小孩记忆力差是什么原因| 为什么床上有蚂蚁| 人格的核心是什么| 诗和远方是什么意思| 热痱子是什么原因引起的| 胎盘长什么样子图片| 澎湃的什么| 12月是什么座| 长期大便不成形是什么原因造成的| hopeshow是什么牌子| 鹞是什么意思| 做健身教练有什么要求| 什么祛斑产品效果好| a1代表什么意思| 硫磺皂有什么作用| bmd是什么意思| 东莞有什么好玩的地方| 丘疹是什么原因引起的| 菜花是什么| 必迈跑鞋什么档次| 亚麻籽吃了有什么好处| 双侧下鼻甲肥大是什么意思| 鎏是什么意思| 头发厚适合剪什么发型| 什么泡水喝治口臭| 三鹿奶粉现在叫什么| 尿胆原高是什么原因| 水宝宝是什么| 组织部副部长是什么级别| 蛇脱皮在家有什么预兆| 愿闻其详是什么意思| 盼头是什么意思| 下呼吸道感染吃什么药| 三叉神经痛挂什么科| 初音未来是什么| 尿隐血是什么原因引起的| 儿童吃手指是什么原因| 日逼是什么意思| 扁桃体长什么样子| 尿的颜色有点红褐色是什么原因| 什么样的小鸟| 抗hbc阳性是什么意思| 蔗糖素是什么| 考教师资格证需要什么条件| 9k金是什么意思| 肾阳虚是什么意思| 荷花五行属什么| 低血糖中医叫什么病| 直肠炎是什么原因引起| 受精卵发育成什么| 光敏树脂是什么材料| 雌二醇过高是什么原因| 为什么睡不醒| 晚上梦见蛇是什么预兆| 肌酐高吃什么食物| 姜粉什么时候喝最好| 玫瑰疹是什么病| 不置可否是什么意思| 江西老表是什么意思| 碱性磷酸酶高是什么意思| 车万是什么意思| 珉字五行属什么| 九浅一深什么意思| 字是什么结构| 元旦北京有什么好玩的| kenzo属于什么档次| 手上螺纹多少代表什么| 枸杞子有什么功效| 洁面液是干什么用的| 头发没有光泽是什么原因| 百度
Namespaces
Variants
Actions

用车|驾照自学直考:车辆改装成本高 推广有难

From cppreference.com
< cpp‎ | language
 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 
百度 外观方面,第六代M5在以形式服从功能的核心,采用大尺寸前进气格栅、三段式前包围、楔形外后视镜、车尾底部空气扩散器等空气动力学设计,能够带来更低的风阻和更好的下压力。

Most C++ projects use multiple translation units, and so they need to share declarations and definitions across those units. The usage of headers is prominent for this purpose, an example being the standard library whose declarations can be provided by including the corresponding header.

Modules are a language feature to share declarations and definitions across translation units. They are an alternative to some use cases of headers.

Modules are orthogonal to namespaces.

// helloworld.cpp
export module helloworld; // module declaration
 
import <iostream>;        // import declaration
 
export void hello()       // export declaration
{
    std::cout << "Hello world!\n";
}
// main.cpp
import helloworld; // import declaration
 
int main()
{
    hello();
}

Contents

[edit] Syntax

export(optional) module module-name module-partition (optional) attr (optional) ; (1)
export declaration (2)
export { declaration-seq (optional) } (3)
export(optional) import module-name attr (optional) ; (4)
export(optional) import module-partition attr (optional) ; (5)
export(optional) import header-name attr (optional) ; (6)
module; (7)
module : private; (8)
1) Module declaration. Declares that the current translation unit is a module unit.
2,3) Export declaration. Export all namespace-scope declarations in declaration or declaration-seq.
4,5,6) Import declaration. Import a module unit/module partition/header unit.

[edit] Module declarations

A translation unit may have a module declaration, in which case it is considered a module unit. The module declaration, if provided, must be the first declaration of the translation unit (excepted the global module fragment, which is covered later on). Each module unit is associated to a module name (and optionally a partition), provided in the module declaration.

export(optional) module module-name module-partition (optional) attr (optional) ;

The module name consists of one or more identifiers separated by dots (for example: mymodule, mymodule.mysubmodule, mymodule2...). Dots have no intrinsic meaning, however they are used informally to represent hierarchy.

If any identifier in the module name or module partition is defined as an object-like macro, the program is ill-formed.

A named module is the collection of module units with the same module name.

Module units whose declaration has the keyword export are termed module interface units; all other module units are termed module implementation units.

For every named module, there must be exactly one module interface unit that specifies no module partition; this module unit is termed the primary module interface unit. Its exported content will be available when importing the corresponding named module.

// (each line represents a separate translation unit)
 
export module A;   // declares the primary module interface unit for named module 'A'
module A;          // declares a module implementation unit for named module 'A'
module A;          // declares another module implementation unit for named module 'A'
export module A.B; // declares the primary module interface unit for named module 'A.B'
module A.B;        // declares a module implementation unit for named module 'A.B'

[edit] Exporting declarations and definitions

Module interface units can export declarations (including definitions), which can be imported by other translation units. To export a declaration, either prefix it with the export keyword, or else place it inside an export block.

export declaration
export { declaration-seq (optional) }
export module A; // declares the primary module interface unit for named module 'A'
 
// hello() will be visible by translations units importing 'A'
export char const* hello() { return "hello"; } 
 
// world() will NOT be visible.
char const* world() { return "world"; }
 
// Both one() and zero() will be visible.
export
{
    int one()  { return 1; }
    int zero() { return 0; }
}
 
// Exporting namespaces also works: hi::english() and hi::french() will be visible.
export namespace hi
{
    char const* english() { return "Hi!"; }
    char const* french()  { return "Salut!"; }
}

[edit] Importing modules and header units

Modules are imported via an import declaration:

export(optional) import module-name attr (optional) ;

All declarations and definitions exported in the module interface units of the given named module will be available in the translation unit using the import declaration.

Import declarations can be exported in a module interface unit. That is, if module B export-imports A, then importing B will also make visible all exports from A.

In module units, all import declarations (including export-imports) must be grouped after the module declaration and before all other declarations.

/////// A.cpp (primary module interface unit of 'A')
export module A;
 
export char const* hello() { return "hello"; }
 
/////// B.cpp (primary module interface unit of 'B')
export module B;
 
export import A;
 
export char const* world() { return "world"; }
 
/////// main.cpp (not a module unit)
#include <iostream>
import B;
 
int main()
{
    std::cout << hello() << ' ' << world() << '\n';
}

#include should not be used in a module unit (outside the global module fragment), because all included declarations and definitions would be considered part of the module. Instead, headers can also be imported as header units with an import declaration:

export(optional) import header-name attr (optional) ;

A header unit is a separate translation unit synthesized from a header. Importing a header unit will make accessible all its definitions and declarations. Preprocessor macros are also accessible (because import declarations are recognized by the preprocessor).

However, contrary to #include, preprocessing macros already defined at the point of the import declaration will not affect the processing of the header. This may be inconvenient in some cases (some headers use preprocessing macros as a form of configuration), in which case the usage of global module fragment is needed.

/////// A.cpp (primary module interface unit of 'A')
export module A;
 
import <iostream>;
export import <string_view>;
 
export void print(std::string_view message)
{
    std::cout << message << std::endl;
}
 
/////// main.cpp (not a module unit)
import A;
 
int main()
{
    std::string_view message = "Hello, world!";
    print(message);
}

[edit] Global module fragment

Module units can be prefixed by a global module fragment, which can be used to include headers when importing the headers is not possible (notably when the header uses preprocessing macros as configuration).

module;

preprocessing-directives (optional)

module-declaration

If a module-unit has a global module fragment, then its first declaration must be module;. Then, only preprocessing directives can appear in the global module fragment. Then, a standard module declaration marks the end of the global module fragment and the start of the module content.

/////// A.cpp (primary module interface unit of 'A')
module;
 
// Defining _POSIX_C_SOURCE adds functions to standard headers,
// according to the POSIX standard.
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
 
export module A;
 
import <ctime>;
 
// Only for demonstration (bad source of randomness).
// Use C++ <random> instead.
export double weak_random()
{
    std::timespec ts;
    std::timespec_get(&ts, TIME_UTC); // from <ctime>
 
    // Provided in <stdlib.h> according to the POSIX standard.
    srand48(ts.tv_nsec);
 
    // drand48() returns a random number between 0 and 1.
    return drand48();
}
 
/////// main.cpp (not a module unit)
import <iostream>;
import A;
 
int main()
{
    std::cout << "Random value between 0 and 1: " << weak_random() << '\n';
}

[edit] Private module fragment

Primary module interface unit can be suffixed by a private module fragment, which allows a module to be represented as a single translation unit without making all of the contents of the module reachable to importers.

module : private;

declaration-seq (optional)

Private module fragment ends the portion of the module interface unit that can affect the behavior of other translation units. If a module unit contains a private module fragment, it will be the only module unit of its module.

export module foo;
 
export int f();
 
module : private; // ends the portion of the module interface unit that
                  // can affect the behavior of other translation units
                  // starts a private module fragment
 
int f()           // definition not reachable from importers of foo
{
    return 42;
}

[edit] Module partitions

A module can have module partition units. They are module units whose module declarations include a module partition, which starts with a colon : and is placed after the module name.

export module A:B; // Declares a module interface unit for module 'A', partition ':B'.

A module partition represents exactly one module unit (two module units cannot designate the same module partition). They are visible only from inside the named module (translation units outside the named module cannot import a module partition directly).

A module partition can be imported by module units of the same named module.

export(optional) import module-partition attr (optional) ;
/////// A-B.cpp   
export module A:B;
...
 
/////// A-C.cpp
module A:C;
...
 
/////// A.cpp
export module A;
 
import :C;
export import :B;
 
...

All definitions and declarations in a module partition are visible by the importing module unit, whether exported or not.

Module partitions can be module interface units (when their module declarations have export). They must be export-imported by the primary module interface unit, and their exported statements will be visible when the module is imported.

export(optional) import module-partition attr (optional) ;
///////  A.cpp   
export module A;     // primary module interface unit
 
export import :B;    // Hello() is visible when importing 'A'.
import :C;           // WorldImpl() is now visible only for 'A.cpp'.
// export import :C; // ERROR: Cannot export a module implementation unit.
 
// World() is visible by any translation unit importing 'A'.
export char const* World()
{
    return WorldImpl();
}
/////// A-B.cpp 
export module A:B; // partition module interface unit
 
// Hello() is visible by any translation unit importing 'A'.
export char const* Hello() { return "Hello"; }
/////// A-C.cpp 
module A:C; // partition module implementation unit
 
// WorldImpl() is visible by any module unit of 'A' importing ':C'.
char const* WorldImpl() { return "World"; }
/////// main.cpp 
import A;
import <iostream>;
 
int main()
{
    std::cout << Hello() << ' ' << World() << '\n';
    // WorldImpl(); // ERROR: WorldImpl() is not visible.
}

[edit] Module ownership

In general, if a declaration appears after the module declaration in a module unit, it is attached to that module.

If a declaration of an entity is attached to a named module, that entity can only be defined in that module. All declarations of such an entity must be attached to the same module.

If a declaration is attached to a named module, and it is not exported, the declared name has module linkage.

export module lib_A;
 
int f() { return 0; } // f has module linkage
export int x = f();   // x equals 0
export module lib_B;
 
int f() { return 1; } // OK, f in lib_A and f in lib_B refer to different entities
export int y = f(); // y equals 1

If two declarations of an entity are attached to different modules, the program is ill-formed; no diagnostic is required if neither is reachable from the other.

/////// decls.h
int f(); // #1, attached to the global module
int g(); // #2, attached to the global module
/////// Module interface of M
module;
#include "decls.h"
export module M;
export using ::f; // OK, does not declare an entity, exports #1
int g();          // Error: matches #2, but attached to M
export int h();   // #3
export int k();   // #4
/////// Other translation unit
import M;
static int h();   // Error: matches #3
int k();          // Error: matches #4

The following declarations are not attached to any named module (and thus the declared entity can be defined outside the module):

export module lib_A;
 
namespace ns // ns is not attached to lib_A.
{
    export extern "C++" int f(); // f is not attached to lib_A.
           extern "C++" int g(); // g is not attached to lib_A.
    export              int h(); // h is attached to lib_A.
}
// ns::h must be defined in lib_A, but ns::f and ns::g can be defined elsewhere (e.g.
// in a traditional source file).

[edit] Notes

Feature-test macro Value Std Feature
__cpp_modules 201907L (C++20) Modules — core language support
__cpp_lib_modules 202207L (C++23) Standard library modules std and std.compat

[edit] Keywords

private, module, import, export

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
CWG 2732 C++20 it was unclear whether importable headers can
react to preprocessor state from the point of import
no reaction
P3034R1 C++20 module names and module partitions could
contain identifiers defined as object-like macros
prohibited
早期胃癌有什么症状 脾虚喝什么泡水比较好 斑秃去医院挂什么科 考试前吃巧克力有什么好处 孙尚香字什么
感冒发烧吃什么好 中段尿是什么意思 碳酸氢钠有什么作用 补肾虚吃什么药最好 宠辱不惊是什么意思
便秘吃什么药最好 控评是什么意思 双清是什么意思 血管明显是什么原因 眼压是什么
什么药可以推迟月经 贝壳像什么 小孩瘦小不长肉是什么原因 灰面是什么面粉 什么是机械表
孕妇喉咙痛吃什么好得最快hcv9jop0ns4r.cn 七匹狼男装是什么档次hcv8jop8ns2r.cn 性出血是什么原因造成的呢要怎么办hcv8jop5ns8r.cn 家里为什么有跳蚤hcv8jop1ns9r.cn 总是想睡觉是什么原因hcv8jop1ns4r.cn
绿茶男是什么意思hcv8jop2ns1r.cn 起薪是什么意思hcv9jop3ns7r.cn 爱居兔女装是什么档次creativexi.com 西同念什么hcv9jop0ns1r.cn 藿香正气水不能和什么药一起吃0735v.com
10.28是什么星座hcv7jop7ns1r.cn 人到无求品自高什么意思hcv8jop7ns0r.cn 窦骁父母是干什么的wuhaiwuya.com 就诊卡是什么hcv8jop9ns9r.cn 面试要带什么imcecn.com
南辕北辙是什么故事hcv8jop6ns9r.cn 什么的贾宝玉hcv9jop4ns9r.cn 孤儿是什么意思hcv9jop0ns5r.cn 什么情况需要做肠镜hcv8jop4ns7r.cn 大熊猫生活在什么地方hcv9jop2ns2r.cn
百度