且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c++ - 如何在c ++模板中执行if else依赖类型?

更新时间:2022-06-11 02:04:51

你可以使用 typeid:

if (typeid(T) == typeid(int))

或者你可以使用 std::is_same 类型特征:

Or you could use the std::is_same type trait:

if (std::is_same<T, int>::value)