Most efficient way to find the greatest of three ints

前端 未结 14 1295
离开以前
离开以前 2020-12-30 07:58

Below is my pseudo code.

function highest(i, j, k)
{
  if(i > j && i > k)
  {
    return i;
  }
  else         


        
14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 08:42

    There is a proposal to include this into the C++ library under N2485. The proposal is simple, so I've included the meaningful code below. Obviously, this assumes variadic templates

    template < typename T >
    const T & max ( const T & a )
    { return a ; }
    
    template < typename T , typename ... Args >
    const T & max( const T & a , const T & b , const Args &... args )
    { return  max ( b > a ? b : a , args ...); }
    

提交回复
热议问题