문제

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top