C++17的新特性

我记得我刚开始接触C++的时候,C++11标准刚刚出炉。C++14还没玩转,C++17又来了,转眼间5、6过去了,小白变大白。

在前不久的一次C++委员会上最终敲定了C++17/C++1z标准。

标准有了,那么各个编译器什么时候能实现呢?静等。

下面我总结一下C++17的主要特性,详细信息访问 https://www.reddit.com/r/cpp/comments/4pmlpz/what_the_iso_c_committee_added_to_the_c17_working/

C++17标准的主要特性

std::variant

variant包含一个不同于union的泛型类,用于在存储和操作来自于不同类型的对象。这个库的一个特点是支持类型安全的访问,减少了不同数据类型的类型转换代码的共同问题。

std::variant是根据boost::variant和其它variant库设计的。它的API和boost::variant相似。

The implications of the consensus variant design are well understood and have been explored over several LEWG discussions, over a thousand emails, a joint LEWG/EWG session, and not to mention 12 years of experience with Boost and other libraries. The last major change made to the proposal was non-breaking and added exception throws where previously there was undefined behavior. Since then, all suggested modifications have been cosmetic, rehashes of older discussions, or would be handled just as well by defect resolutions.

模版中的auto

C++14添加了lambda使用auto做为参数,Declaring non-type template arguments with auto允许使用auto替换class或typename。也可以在可变参数模版上使用,例如 template<auto… a>。

发表评论

电子邮件地址不会被公开。 必填项已用*标注