What does the 'void()' in 'auto f(params) -> decltype(…, void())' do?

后端 未结 1 1770
-上瘾入骨i
-上瘾入骨i 2020-12-24 10:40

I found code here that looked something like this:

auto f(T& t, size_t n) -> decltype(t.reserve(n), void()) { .. }

In all the docume

相关标签:
1条回答
  • 2020-12-24 11:10

    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.

    That code is using SFINAE - it's enabled if t.reserve(n) exists but it wants to keep the return type as void.

    0 讨论(0)
提交回复
热议问题