当前位置:网站首页>std::is_ union,std::is_ class,std::integral_ constant

std::is_ union,std::is_ class,std::integral_ constant

2022-07-04 08:25:00 pickled cabbage

#include <iostream>
#include <string>
using namespace std;

struct A {
    
    int num;
    char type;
};
union B {
    
    int num;
    char type;
};

int main()
{
    
    /*std::is_union Is a class template . Used to determine whether a type is a union type   If it's a coalition ,value for true(1), Otherwise false(0), The judgment principle is related to some internal practices of the compiler */
    cout << std::is_union<A>::value << endl; 
    cout << std::is_union<B>::value << endl;

    /*cpp17*/
    cout << std::is_union_v<A> << endl; 
    cout << std::is_union_v<B> << endl;

    /*std::is_class Is a class template . Used to judge whether a type is a class type ( Union is not a class type ). */
    cout << std::is_class<A>::value << endl;
    cout << std::is_class<B>::value << endl;

    /*cpp17*/
    cout << std::is_class_v<A> << endl;
    cout << std::is_class_v<B> << endl;

    /*std::integral_constant, Is a class for packaging purposes  * C++11 Class template introduced by the new standard . */
    cout << std::integral_constant<int, 15>::value << endl;
    cout << std::integral_constant<bool, true>::value << endl;
    return 0;
}

 Insert picture description here

原网站

版权声明
本文为[pickled cabbage]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141458299234.html