std::is_void(C++11)主要用于判断指定类型是否为void,注意这里的void包括 void, const void, volatile void 及const volatile void。
可能实现为:
template<class T>
struct is_void: std::is_same<void, typename std::remove_cv<T>::type> {};
实例:
#include <iostream>
using namespace std;
int main()
{
cout << std::is_void<void>::value << endl;
cout << std::is_void<const void>::value << endl;
cout << std::is_void<volatile void>::value << endl;
cout << std::is_void<const volatile void>::value << endl;
cout << std::is_void<bool>::value << endl;
system("PAUSE");
}
运行结果为:
源码见:https://github.com/devsave/TypeTraits