General min and max - C++

前端 未结 2 1089
礼貌的吻别
礼貌的吻别 2021-01-12 02:25

Writing a general minimum function, Two questions came to my mind. The code works fine with any input type and different argument number:

namespace xyz
{

te         


        
2条回答
  •  遥遥无期
    2021-01-12 02:49

    std::common_type(c++11):

    For non-specialized std::common_type, the rules for determining the common type between every pair T1, T2 are exactly the rules for determining the return type of the ternary conditional operator where T1 and T2 are the types of its second and the third operands.

    and

    For arithmetic types, the common type may also be viewed as the type of the (possibly mixed-mode) arithmetic expression such as T0() + T1() + ... + Tn().

    Not sure about const&, but you could play with std::remove_cv and std::remove_reference (and std::is_reference to find out the answer).

    In fact, here's a list of type support utilities. Knock yourself out.

提交回复
热议问题