[英]What are the new features in C++17?
C++17 is now feature complete, so unlikely to experience large changes. C++17 现在功能完整,所以不太可能经历大的变化。 Hundreds of proposals were put forward for C++17.
为 C++17 提出了数百个提案。
Which of those features were added to C++ in C++17?在 C++17 中,C++ 中添加了哪些特性?
When using a C++ compiler that supports "C++1z", which of those features are going to be available when the compiler updates to C++17?当使用支持“C++1z”的 C++ 编译器时,当编译器更新到 C++17 时,哪些特性将可用?
Template argument deduction for class templates 类模板的模板参数推导
( Folding + ... + expressions ) and Revisions (折叠 + ... + 表达式)和修订
constexpr lambdas constexpr lambdas
Capturing *this
in lambdas 在 lambdas 中捕获
*this
[*this]{ std::cout << could << " be " << useful << '\\n'; }
[[fallthrough]]
, [[nodiscard]]
, [[maybe_unused]]
attributes [[fallthrough]]
, [[nodiscard]]
, [[maybe_unused]]
属性
[[attributes]]
on namespace
s and enum { erator[[s]] }
[[attributes]]
在namespace
s 和enum { erator[[s]] }
using
in attributes to avoid having to repeat an attribute namespace. using
in 属性以避免重复属性命名空间。
Compilers are now required to ignore non-standard attributes they don't recognize .现在要求编译器忽略他们不认识的非标准属性。
Simple static_assert(expression);
简单的
static_assert(expression);
with no string没有字符串
no throw
unless throw()
, and throw()
is noexcept(true)
. 除非
throw()
, 否则不throw
,而throw()
是noexcept(true)
。
std::tie
with auto
std::tie
与auto
const auto [it, inserted] = map.insert( {"foo", bar} );
it
and inserted
with deduced type from the pair
that map::insert
returns.it
并inserted
从与推定的类型pair
那个map::insert
回报。std::array
s and relatively flat structsstd::array
和相对扁平的结构if (init; condition)
and switch (init; condition)
if (init; condition)
和switch (init; condition)
if (const auto [it, inserted] = map.insert( {"foo", bar} ); inserted)
if(decl)
to cases where decl
isn't convertible-to-bool sensibly.if(decl)
扩展到decl
不能明智地转换为 bool 的情况。 Generalizing range-based for loops 泛化基于范围的 for 循环
Dynamic memory allocation for over-aligned data 过度对齐数据的动态内存分配
Guaranteed copy elision 保证复制省略
Fixed order-of-evaluation for (some) expressions with some modifications 修复了(某些)表达式的计算顺序,并进行了一些修改
.then
on future work..then
用于未来的工作。Forward progress guarantees (FPG) (also, FPGs for parallel algorithms )前向进度保证 (FPG)(还有用于并行算法的FPG)
u8'U', u8'T', u8'F', u8'8'
character literals (string already existed) u8'U', u8'T', u8'F', u8'8'
字符字面量(字符串已经存在)
inherited constructors fixes to some corner cases (see P0136R0 for examples of behavior changes) 继承的构造函数修复了某些极端情况(有关行为更改的示例,请参阅P0136R0 )
std::string
like reference-to-character-array or substring std::string
类似于对字符数组或子std::string
引用string const&
again.string const&
了。 Also can make parsing a bajillion times faster."hello world"sv
char_traits
char_traits
std::byte
off more than they could chew. std::byte
比他们可以咀嚼的还要多。
std::invoke
std::apply
std::make_from_tuple
, std::apply
applied to object construction std::make_from_tuple
, std::apply
应用于对象构造
is_invocable
, is_invocable_r
, invoke_result
is_invocable
, is_invocable_r
, invoke_result
result_of
result_of
is_invocable<Foo(Args...), R>
is "can you call Foo
with Args...
and get something compatible with R
", where R=void
is default. is_invocable<Foo(Args...), R>
是“你能用Args...
调用Foo
Args...
并获得与R
兼容的东西”,其中R=void
是默认值。invoke_result<Foo, Args...>
is std::result_of_t<Foo(Args...)>
but apparently less confusing? invoke_result<Foo, Args...>
是std::result_of_t<Foo(Args...)>
但显然不那么令人困惑? [class.directory_iterator]
and [class.recursive_directory_iterator]
[class.directory_iterator]
和[class.recursive_directory_iterator]
[class.directory_iterator]
[class.recursive_directory_iterator]
fstream
s can be opened with path
s, as well as with const path::value_type*
strings. fstream
s 可以用path
s 打开,也可以用const path::value_type*
字符串打开。
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添加用于线程目的,即使您不使用线程也会暴露
atomic<T>
::is_always_lockfree
atomic<T>
::is_always_lockfree
std::lock
pain when locking more than one mutex at a time.std::lock
痛苦。std
algorithms, and related machinery std
算法的并行版本和相关机制[func.searchers]
and [alg.search]
[func.searchers]
和[alg.search]
std::function
for allocatorsstd::function
std::sample
, sampling from a range? std::sample
,从一个范围采样?
try_emplace
and insert_or_assign
try_emplace
和insert_or_assign
Splicing for map<>
, unordered_map<>
, set<>
, and unordered_set<>
拼接
map<>
、 unordered_map<>
、 set<>
和unordered_set<>
non-member std::size
, std::empty
, std::data
非成员
std::size
、 std::empty
、 std::data
std::begin
/ end
std::begin
/ end
The emplace
family of functions now returns a reference to the created object . emplace
系列函数现在返回对创建对象的引用。
unique_ptr<T[]>
fixes and other unique_ptr
tweaks. unique_ptr<T[]>
修复和其他unique_ptr
调整。weak_from_this
and some fixed to shared from this weak_from_this
和一些固定到共享的std
datatype improvements:std
数据类型改进:{}
construction of std::tuple
and other improvements {}
构造std::tuple
和其他改进C++17 library is based on C11 instead of C99 C++17 库基于C11 而不是 C99
Reserved std[0-9]+
for future standard libraries为未来的标准库保留
std[0-9]+
destroy(_at|_n)
, uninitialized_move(_n)
, uninitialized_value_construct(_n)
, uninitialized_default_construct(_n)
destroy(_at|_n)
, uninitialized_move(_n)
, uninitialized_value_construct(_n)
, uninitialized_default_construct(_n)
std
implementations exposedstd
实现中已经公开的实用程序代码std::clamp()
std::clamp( a, b, c ) == std::max( b, std::min( a, c ) )
roughly std::clamp( a, b, c ) == std::max( b, std::min( a, c ) )
大致gcd
and lcm
gcd
和lcm
std::uncaught_exceptions
std::as_const
std::bool_constant
_v
template variables _v
模板变量std::void_t<T>
std::owner_less<void>
std::less<void>
, but for smart pointers to sort based on contentsstd::less<void>
,但用于基于内容排序的智能指针std::chrono
polish std::chrono
波兰语std::conjunction
, std::disjunction
, std::negation
exposed std::conjunction
, std::disjunction
, std::negation
暴露std::not_fn
std
std
noexcept 的规则std::less
.std::less
。<codecvt>
memory_order_consume
result_of
, replaced with invoke_result
result_of
,替换为invoke_result
shared_ptr::unique
, it isn't very threadsafe shared_ptr::unique
,它不是很线程安全Isocpp.org has has an independent list of changes since C++14; Isocpp.org 拥有自 C++14 以来的独立变更列表; it has been partly pillaged.
它已被部分掠夺。
Naturally TS work continues in parallel, so there are some TS that are not-quite-ripe that will have to wait for the next iteration.自然地,TS 工作并行继续,因此有些 TS 还不够成熟,必须等待下一次迭代。 The target for the next iteration is C++20 as previously planned, not C++19 as some rumors implied.
下一次迭代的目标是之前计划的 C++20,而不是一些传言暗示的 C++19。 C++1O has been avoided.
已避免使用 C++1O。
Initial list taken from this reddit post and this reddit post , with links added via googling or from the above isocpp.org page.从这个 reddit 帖子和这个 reddit 帖子中获取的初始列表,通过谷歌搜索或从上面的 isocpp.org 页面添加了链接。
Additional entries pillaged from SD-6 feature-test list.从SD-6功能测试列表中掠夺的其他条目。
clang's feature list and library feature list are next to be pillaged. clang 的功能列表和库功能列表即将被掠夺。 This doesn't seem to be reliable, as it is C++1z, not C++17.
这似乎不可靠,因为它是 C++1z,而不是 C++17。
these slides had some features missing elsewhere. 这些幻灯片在其他地方缺少一些功能。
While "what was removed" was not asked, here is a short list of a few things ((mostly?) previous deprecated) that are removed in C++17 from C++:虽然没有询问“删除了什么”,但这里列出了在 C++17 中从 C++ 中删除的一些内容((大部分?)以前已弃用):
register
, keyword reserved for future use register
,保留供将来使用的关键字bool b; ++b;
<functional>
stuff, random_shuffle
<functional>
东西, random_shuffle
std::function
std::function
分配器There were rewordings.有改写。 I am unsure if these have any impact on code, or if they are just cleanups in the standard:
我不确定这些是否对代码有任何影响,或者它们是否只是标准中的清理:
P0512R0 (template argument deduction tweaks) P0512R0 (模板参数推导调整)
P0509R1 (updating restrictions on exception handling) P0509R1 (更新异常处理限制)
P0012R1 (make exception specifications be part of the type system) P0012R1 (使异常规范成为类型系统的一部分)
P0504R0 (tags for optional/variant/any) P0504R0 (可选/变体/任何标签)
P0508R0 (structured bindings node handles) P0508R0 (结构化绑定节点句柄)
P0521R0 (shared pointer use count and unique changes?) P0521R0 (共享指针使用计数和唯一更改?)
https://isocpp.org/files/papers/p0636r0.html https://isocpp.org/files/papers/p0636r0.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.