A R*_*A R 9 c++ string templates vector c++20
我目前正在使用 Visual Studio 2022 Update 17.1.6,我发现导出类型别名有一些有趣的东西。由于我不明白的原因,当我导出某些数据类型的类型别名(例如std::vector<std::string>在模块接口文件中)时,我可以在导入它的文件中使用std::vector<>和。std::string例如:
modInterface.ixx
export module words;
import <iostream>
import <vector>;
import <string>;
...
export using Words = std::vector<std::string>;
...
Run Code Online (Sandbox Code Playgroud)
在内部分区中:
modInternalPartition.cpp
module words:wordsIP;
import words;
//This compiles as expected
Words wordStorage;
//Why does my compiler sees below as correct, and compiles it without error?
std::vector<int> numStorage = { 1, 2, 3, 4 };
//Why does my compiler also sees below as correct, and compiles it without error?
std::string text = "This dish is tasty";
//This would produce an error, which is expected since I did not export import <iostream> in modInterface.ixx
std::cout << text;
...
Run Code Online (Sandbox Code Playgroud)
我的第一个想法是,既然Words是类型别名,那么导出它就意味着导出std::vector<>and std::string,但是既然std::vector<>是模板,为什么不只导出 it ( std::vector<std::string>) 的实例化呢?