设为首页 加入收藏

TOP

C++20 的 Modules(二)
2019-07-12 18:10:50 】 浏览:116
Tags:Modules
增量编译速度~

-------------华丽分割线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 BeastReachability & Visibility 巴拉巴拉,大家可以参考上面两篇文章……

个人觉得 Modules 作为重量级特性,还是给 C++ 带来了革新。引用一句某老外的说法:“Make CPP great again!”。

期待编译器这边的实现和新的 Build System 及可能的包管理工具,貌似一直在推进。

------- Over -------

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇洛谷 P3373 【模板】线段树 2 下一篇HelloWorld! C++纠错版

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目