增量编译速度~
-------------华丽分割线3--------------
考虑到程序员编码的方便性,标准规定了五花八门的 export 语法。如下所示,我们来欣赏一下。
// Export everything within the block.
export
{
int some_number = 123;
class foo
{
public:
void invoke() { }
private:
int count_ = 0;
};
}
// Export namespace.
export namespace demo::test
{
struct tips
{
int abc;
}
void free_func() { }
}
// Export a free function.
export void here_is_a_function() { }
// Export a global variable.
export int global_var = 123;
// Export a class.
export class test
{
};
下面几种是非法的 export 写法,是无法编译的。
// Anonymous namespace cannot be exported.
export namespace
{
}
// Cannot export static variables.
export static int static_variable = 123;
// Cannot export static functions.
export static void foo()
{
}
// OK, export a namespace.
export namespace test
{
// Error, cannot define static members in an exported namespace.
static int mine = 123;
// Error, as mentioned above.
static void geek() { }
}
-------------华丽分割线4--------------
文中还介绍了其他的一些坑,比如 Implementation Unit Beast 、Reachability & Visibility 巴拉巴拉,大家可以参考上面两篇文章……
个人觉得 Modules 作为重量级特性,还是给 C++ 带来了革新。引用一句某老外的说法:“Make CPP great again!”。
期待编译器这边的实现和新的 Build System 及可能的包管理工具,貌似一直在推进。
------- Over -------