std::ignore
忽略未使用的变量是一种好方法吗?
假设我有这样的功能:
void func(int i)
{
//for some reason, I don't need i anymore but I cannot change signature of function
std::ignore = i;
}
附加信息
这是一个例子,一些答案建议使用匿名变量。但是对于其他情况,我该怎么做,例如:
int Thread_UnSafe_func_returnSomething():
void func()
{
// To make it thread safe
// Also it is required to call only once
static int i = Thread_UnSafe_func_returnSomething();
std::ignore = i;
}