C++ 17中有哪些新功能?

Yak*_*ont 986 c++ standards c++-faq c++17

C++ 17现在功能齐全,因此不太可能经历大的变化.为C++ 17提出了数百个提案.

在C++ 17中,哪些特性被添加到C++中?

当使用支持"C++ 1z"的C++编译器时,当编译器更新到C++ 17时,哪些功能可用?

Yak*_*ont 1248

语言特色:

模板和通用代码

LAMBDA

属性

语法清理

更清洁的多回程和流量控制

  • 结构化绑定

    • 基本上,一流std::tieauto
    • 例:
      • const auto [it, inserted] = map.insert( {"foo", bar} );
      • 创建变量itinserted从与推导的类型pairmap::insert返回.
    • 适用于元组/对喜欢std::array和相对扁平的结构
    • Actually named structured bindings in standard
  • if (init; condition) and switch (init; condition)

    • if (const auto [it, inserted] = map.insert( {"foo", bar} ); inserted)
    • Extends the if(decl) to cases where decl isn't convertible-to-bool sensibly.
  • Generalizing range-based for loops

    • Appears to be mostly support for sentinels, or end iterators that are not the same type as begin iterators, which helps with null-terminated loops and the like.
  • if constexpr

    • Much requested feature to simplify almost-generic code.

Misc

Library additions:

Data types

Invoke stuff

File System TS v1

New algorithms

  • for_each_n

  • reduce

  • transform_reduce

  • exclusive_scan

  • inclusive_scan

  • transform_exclusive_scan

  • transform_inclusive_scan

  • Added for threading purposes, exposed even if you aren't using them threaded

Threading

(parts of) Library Fundamentals TS v1 not covered above or below

Container Improvements

Smart pointer changes

Other std datatype improvements:

Misc