C 的明天——连同明天的明天[1]

2008-02-23 05:40:29来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

  7月15日-20日,标准委员会在Toronto开了一次会,IBM做的东。从会后的文档来看,除了把一些已基本成熟的提案加入草案,进一步明确了打算C 0x的新特性,连同留到再下一版本的C 标准的提案。从中我们能够清楚地看到C 未来,连同未来的未来的发展趋势。文档“State of C Evolution”(http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2007/n2336.html)包含了最新的发展情况。本文便是基于这篇文档。

  首先,是个清单,包含已投票通过,合并到working paper的提案。从编程技术的角度来讲,比较主要的内容包括:

  A Proposal to Add an Rvalue Reference to the C Language

  Template aliases for C

  Variadic Templates

  Delegating Constructors

  Decltype

  Rvalue Reference为C 提供了检测右值引用的能力,使C 具备了move语义和完美转发。

  Template aliases完善了C 的别名体系:

  template

  using MyVector=vector>;

  Vec v; // same as vector> v;

  使我们能够更灵活地创建类型别名。很有用。(真想立即得到他,我急等着用呢)。

  Variadic Template则进步更大。提供了可变的模板类型参数,也就是说,同一个模板的参数的数量是可变的:

  template

  class array { /* implementation */ };

  array rotation_matrix; // 3x3 rotation matrix

  array 3d_array; //3x3x3 array

  Variadic Template使得我们能够拥有真正任意结构的tuple,类型安全的printf()等崭新的基础设施。

  Delegating Constructors使我们能够“复用”一个“基本”的构造函数:

  class X {

  int i_;

  public:

  X( int i ) : i_(i) { }

  X() : X(42) { } // “复用”X(int i)

  };

  这个新特性能够大幅减少构造函数上的重复代码,提高效率。

  Decltype能够使我们提取一个表达式的类型:

  int a=1; float b=2;

  typedef decltype(a b) result_t;

  typedef decltype(string::c_str) cstr_t;

  其他更有一些很有用的特性,诸如static_assert、Generalized Constant Expressions等都很实用,只是不如上述几大特性影响大。

  接下来是一大堆正在审查的提案。分成了7大部分:

  Voting at next meeting。下次会议打算投票表决的提案。现在只有一个Universal Character Names in Literals。

  Proposed wording under review in Core。正在核心语言小组(标准委员会的一个小组,负责核心语言特性相关提案的审查)中审查的提案。这些提案都已有的wording,并都在做最终的周详审查。比较出名的包括:

  <!--[if !supportLists]-->1. <!--[endif]-->A name for the null pointer: nullptr;C 终于能够无需再用0来代表null指针了。

  <!--[if !supportLists]-->2. <!--[endif]-->Initializer lists;一种通用的初始化列表(即{1,2,3,4,5})方案,扩展到了几乎任何类型。

  <!--[if !supportLists]-->3. <!--[endif]-->Explicit Conversion Operators;类型转换操作符是个麻烦制造者,主要因为他是默认implicit转换的。现在,能够为他加上explicit关键字,迫使其必须执行explicit转换。就像explicit constructor相同。

  <!--[if !supportLists]-->4. <!--[endif]-->Inheriting Constructors;能够直接复用基类的构造函数了。通过using default关键字。

  <!--[if !supportLists]-->5. <!--[endif]-->Proposal for new for-loop;想要foreach关键字的人能够满意了,只是依旧使用for关键字:for(int& a : array){…}。

  <!--[if !supportLists]-->6. <!--[endif]-->Sequencing and the concurrency memory model;C 在并发上是够糟糕的,现在大牛们正在给标准做透析呢。

  <!--[if !supportLists]-->7. <!--[endif]-->连同期盼已久的Concept;已有很多的文章写concept了。

  Blessed by evolution - wording available for initial review by Core。提案完整的wording已有了,也提交核心小组。但核心小组还没有深入地研究。比较重要的包括:

  <!--[if !supportLists]-->1. <!--[endif]-->Thread-Local Storage;并发编程中很重要的特性。C 自然不应该落下。

  <!--[if !supportLists]-->2. <!--[endif]-->Member Initializers;能够在类声明中直接为一个成员赋值,相当于默认初始化。很可爱的一个特性。

  <!--[if !supportLists]-->3. <!--[endif]-->General Attributes for C ;attribute,用.net的人肯定很熟悉。挺有用的特性,不知标准委员会的那帮死脑筋怎么看。

  Core issues addressed by specific papers。核心语言的一些问题,大到值得写一整篇paper了。现在只有一个Syntactic Disambiguation Using the Template Keyword

[1] [2]




标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: C 的明天——连同明天的明天[2]

下一篇: 二级C 重点难点分析:多态性[1]

热门词条
热门标签