1. 程式人生 > >dlib庫中,用魔板實現編譯期型別條件判斷

dlib庫中,用魔板實現編譯期型別條件判斷

    /*!A is_same_type 

        This is a template where is_same_type<T,U>::value == true when T and U are the
        same type and false otherwise.   
    !*/

    template <
        typename T,
        typename U
        >
    class is_same_type
    {
    public:
        enum {value = false};
    private:
        is_same_type();
    };

    template <typename T>
    class is_same_type<T,T>
    {
    public:
        enum {value = true};
    private:
        is_same_type();
    };
template <class bptype>
void check() {
	if (is_same_type<bptype, unsigned char>::value){
		cout << "unsigned char type" << endl;
	}
	else {
		cout << "other type" << endl;
	}
}

int main()
{
	check<unsigned char>();
	return 1;
}