Program to implement the is_same_type type trait in c++

前端 未结 1 607
陌清茗
陌清茗 2021-01-07 02:24

HI Could anyone give a sample program to implement the is_same_type type trait in c++?

相关标签:
1条回答
  • 2021-01-07 03:04
    #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;
    }
    
    0 讨论(0)
提交回复
热议问题