本文主要是介绍元编程学习: integral_constant,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用于定义整型常数变量的类,在<type_traits>中广泛应用,最直接的使用是定义了true_type和false_type, 其为对bool类型的特化
#include <iostream>
#include <type_traits>using namespace std;int main()
{std::cout << "This Demo is that type_traits: integral_constant" << std::endl;std::integral_constant<int, 10> int10;std::cout << "The Const Value: " << int10.value << std::endl;std::integral_constant<unsigned short int, 20> shortInt20;std::cout << "The Const Value: " << shortInt20.value << std::endl;std::cout << "Bool Integral_constent " << std::endl;std::cout << "true : " << true_type::value << std::endl;std::cout << "false: " << false_type::value << std::endl;return 0;
}
这篇关于元编程学习: integral_constant的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!