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

荒凉一梦 提交于 2019-12-03 18:38:04

问题


I found code here that looked something like this:

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

In all the documentation I read I was told that decltype is signed as:

decltype( entity )

or

decltype( expression )

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?


回答1:


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.



来源:https://stackoverflow.com/questions/14003366/what-does-the-void-in-auto-fparams-decltype-void-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!