How can I find the largest (in size) of two integer types?

前端 未结 5 1656
独厮守ぢ
独厮守ぢ 2021-02-09 18:02

For instance:

template 
void fun(const Type1 &v1, const Type2 &v2)
{
    largest::type val          


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-09 18:33

    This won't be very feasible. How do you tell the difference between unsigned int and int? You can't use sizeof() because they're both the same "size" in the memory. I think you'll have to roll your own template specialization to handle those cases at which point I'd suggest just using an overloaded function.

提交回复
热议问题