1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
namespace my
{
template < typename A, typename B > // note: unlike std::max(), returns a prvalue
constexpr auto max( const A& a, const B& b ) { return a<b ? b : a ; }
template < typename FIRST, typename... REST > // note: unlike std::max(), returns a prvalue
constexpr auto max( const FIRST& first, const REST&... rest ) { return max( first, max(rest...) ) ; }
}
int main()
{
std::cout << std::fixed << my::max( 11.1, 12 ) << '\n' // 12.00 (common type for double and int is double)
<< my::max( 11.1, 12, 123LL ) << '\n' // 123.00
<< my::max( 11.1, 12, 123LL, 'A', short(1234), 7.9f ) << '\n' ; // 1234.00
}
|