C++中的std::is_compound模板
C++ STL中的std::is_compound模板用于检查类型是否是复合类型,它返回一个布尔值来表示检查结果。
语法 :
template < class T > struct is_compound;
C++
参数 :此模板包含单个参数T(特性类),用于检查T是否为复合类型。
返回值 :此模板返回以下布尔值:
- True :如果类型是复合类型。
- False :如果类型是非复合类型。
以下程序说明了C++ STL中的is_compound模板:
程序1 :
// C++程序,说明
// is_compound模板
#include <iostream>
#include <type_traits>
using namespace std;
//主程序
struct GFG1 {
};
union GFG2 {
int var1;
float var2;
};
int main()
{
cout << boolalpha;
cout << "is_compound:"
<< endl;
cout << "GFG1:"
<< is_compound<GFG1>::value
<< endl;
cout << "GFG2:"
<< is_compound<GFG2>::value
<< endl;
cout << "int:"
<< is_compound<int>::value
<< endl;
cout << "int*:"
<< is_compound<int*>::value
<< endl;
return 0;
}
C++
is_compound:
GFG1:true
GFG2:true
int:false
int*:true
C++
程序2 :
// C++程序,说明
// is_compound模板
#include <iostream>
#include <type_traits>
using namespace std;
class GFG1 {
};
enum class GFG2 { var1,
var2,
var3,
var4
};
//主程序
int main()
{
cout << boolalpha;
cout << "is_compound:"
<< endl;
cout << "GFG1:"
<< is_compound<GFG1>::value
<< endl;
cout << "GFG2:"
<< is_compound<GFG2>::value
<< endl;
cout << "int[10]:"
<< is_compound<int[10]>::value
<< endl;
cout << "int &:"
<< is_compound<int&>::value
<< endl;
cout << "char:"
<< is_compound<char>::value
<< endl;
return 0;
}
C++
is_compound:
GFG1:true
GFG2:true
int[10]:true
int&:true
char:false
C++
程序3 :
// C++程序,说明
// is_compound模板
#include <iostream>
#include <type_traits>
using namespace std;
//驱动程序
int main()
{
class gfg {
};
cout << boolalpha;
cout << "is_compound:"
<< endl;
cout << "int(gfg::*): "
<< is_compound<int(gfg::*)>::value
<< endl;
cout << "float: "
<< is_compound<float>::value
<< endl;
cout << "double: "
<< is_compound<double>::value
<< endl;
cout << "int(int): "
<< is_compound<int(int)>::value
<< endl;
return 0;
}
C++
is_compound:
int(gfg::*): true
float: false
double: false
int(int): true
C++