在 C++ 中实现 is_same_type 类型特征的程序 [英] Program to implement the is_same_type type trait in c++
本文介绍了在 C++ 中实现 is_same_type 类型特征的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI 谁能给出一个示例程序来在 C++ 中实现 is_same_type 类型特征?
HI Could anyone give a sample program to implement the is_same_type type trait in c++?
推荐答案
#include <iostream>
template< typename T1, typename T2 >
struct is_same_type { enum { result = false }; };
template< typename T>
struct is_same_type<T,T> { enum { result = true }; };
int main()
{
std::cout << is_same_type<int,float>::result << '\n'
<< is_same_type<char,char>::result << '\n';
return 0;
}
这篇关于在 C++ 中实现 is_same_type 类型特征的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文