判断是否为数组类型
#include <iostream>
#include <memory.h>
#include <type_traits>
using namespace std;
int main()
{
std::cout << "This Demo: is_array" << std::endl;
int a = 10;
int b[3] = {10, 11, 12};
int *c = new int[3];
memset(c, 0, sizeof(int) * 3);
int d[] = {10, 11, 13};
if(std::is_array<decltype (a)>::value)
{
std::cout << __LINE__ << ": is array type" << std::endl;
}
else
{
std::cout << __LINE__ << ": isn't array type" << std::endl;
}
if(std::is_array<decltype (b)>::value)
{
std::cout << __LINE__ << ": is array type" << std::endl;
}
else
{
std::cout << __LINE__ << ": isn't array type" << std::endl;
}
if(std::is_array<decltype (c)>::value)
{
std::cout << __LINE__ << ": is array type" << std::endl;
}
else
{
std::cout << __LINE__ << ": isn't array type" << std::endl;
}
if(std::is_array<decltype (d)>::value)
{
std::cout << __LINE__ << ": is array type" << std::endl;
}
else
{
std::cout << __LINE__ << ": isn't array type" << std::endl;
}
delete []c;
c = nullptr;
return 0;
}