第二个学习的是ignore_unused,
template <typename... Ts>
inline void ignore_unused(Ts const& ...)
{}
ignore_unused使用可变参数模板,可以支持任意数量,任意类型的变量,把它们作为函数的参数‘使用’了一下,骗过了编译器,达到了与(void)var相同的效果。
#include<boost\core\ignore_unused.hpp>
using namespace boost;
int func(int x,int y)
{
int i;
ignore_unused(i, x);
return y;
}
int main()
{
int func();
}
如果不加ignore_unused,编译器会报出警告信息。
下面的函数内部定义了一个typedef,然后用ignore_unused忽略:
void func2()
{
typedef int result_type;
ignore_unused<result_type>();
}