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

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

For instance:

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


        
5条回答
  •  情话喂你
    2021-02-09 18:22

    template
    struct is_cond {
        typedef T1 type;
    };
    
    template
    struct is_cond {
        typedef T2 type;
    };
    
    template
    struct largest {
         typedef typename is_cond< (sizeof(T1)>sizeof(T2)), T1, T2>::type type;
    };
    

提交回复
热议问题