头文件
boost/core/ignore_unused.hpp
作用
C++中,没有使用的变量,在编译期间,会出现警告,ingnore_unused就是解决这一问题的。
举例
#include <boost/core/ignore_unused.hpp>
BOOST_CXX14_CONSTEXPR int test_fun(int a)
{
boost::ignore_unused(a);
return 0;
}
int main()
{
{
int a;
boost::ignore_unused(a);
}
{
int a, b;
boost::ignore_unused(a, b);
}
{
int a, b, c;
boost::ignore_unused(a, b, c);
}
{
int a, b, c, d;
boost::ignore_unused(a, b, c, d);
}
{
int a, b, c, d, e;
boost::ignore_unused(a, b, c, d, e);
}
{
typedef int a;
boost::ignore_unused<a>();
}
{
typedef int a;
typedef int b;
boost::ignore_unused<a, b>();
}
{
typedef int a;
typedef int b;
typedef int c;
boost::ignore_unused<a, b, c>();
}
{
typedef int a;
typedef int b;
typedef int c;
typedef int d;
boost::ignore_unused<a, b, c, d>();
}
{
typedef int a;
typedef int b;
typedef int c;
typedef int d;
typedef int e;
boost::ignore_unused<a, b, c, d, e>();
}
{
BOOST_CXX14_CONSTEXPR const int a = test_fun(0);
boost::ignore_unused(a);
}
return 0;
}
源代码
namespace boost {
template <typename... Ts>
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(Ts const& ...)
{}
template <typename... Ts>
BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused()
{}
}
本文详细介绍Boost库中的ignore_unused函数,该函数用于消除C++编译过程中未使用变量产生的警告。文章通过多个实例展示了如何在不同场景下应用此函数,包括普通变量及typedef变量的忽略。

259

被折叠的 条评论
为什么被折叠?



