how to query if(T==int) with template class

前端 未结 9 1756
猫巷女王i
猫巷女王i 2020-12-13 19:43

When I\'m writing a function in a template class how can I find out what my T is?

e.g.

template 
ostream& operator << (os         


        
9条回答
  •  隐瞒了意图╮
    2020-12-13 19:55

    Since C++11 we have std::is_same:

    if (std::is_same::value) ...
    

    It's implemented similar to the suggested trait TypeIsInt suggested in the other answers, but with two types to be compared.

提交回复
热议问题