什么是'void()'在'auto f(params) - > decltype(...,void())'do? [英] What does the 'void()' in 'auto f(params) -> decltype(..., void())' do?
问题描述
我发现代码这里看起来像这样:
I found code here that looked something like this:
auto f(T& t, size_t n) -> decltype(t.reserve(n), void()) { .. }
我读了我被告知, decltype
签署为:
In all the documentation I read I was told that decltype
is signed as:
decltype(entity)
或
decltype(expression)
任何地方都没有第二个参数。至少这是 cppreference 指向的内容。这是 decltype
的第二个参数吗?
And there is no second argument anywhere. At least that's what's pointed to on cppreference. Is this a second argument to decltype
? And if so, what does it do?
推荐答案
因为它是一个表达式,逗号是简单的逗号运算符是rhs类型: void
),而不是另一个参数。
Since it is an expression that comma is simply the comma operator (meaning the type is the type of the rhs side: void
), not another argument.
代码使用SFINAE如果 t.reserve(n)
存在,但它希望保留返回类型为 void
,则启用
That code is using SFINAE - it's enabled if t.reserve(n)
exists but it wants to keep the return type as void
.
这篇关于什么是'void()'在'auto f(params) - > decltype(...,void())'do?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!