On Mon, 30 Nov 2026 17:13:21 +0100, Bonita Montero wrote:
> C++ can do that better:
>
> template<typename Only>
> constexpr Only max( const Only &only )
> {
> return only;
> }
>
> template<typename First, typename Second, typename ... After>
> constexpr common_type_t<First, Second, After ...> max( const First
> &first, const Second &second, const After &... after )
> {
> using common = common_type_t<First, Second, After ...>;
> common larger = first > second ? first : second;
> if constexpr( sizeof ...( after ) != 0 )
> return max( larger, after ... );
> else
> return larger;
> }
That takes a lot of code, and it still cannot cope with
dynamically-generated lists:
Python 3.14.10 (main, Oct 26 2026, 15:12:11) [GCC 16.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> max(2, 3, 5)
5
>>> args = [2, 3, 5]
>>> max(*args)
5