🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2027

Re: variadic min and max, (any some and none, cat and more)

#2027
From: Lawrence D’Oliveiro
Date: Mon, 30 Nov 2026 18:40
32 lines
2128 bytes
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
Technical Details
Message-ID: <11ekfu0$mq5n$4@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11bes8b$1gncr$1@dont-email.me> <11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups: comp.lang.c
Subject: Re: variadic min and max, (any some and none, cat and more)
Date: Mon, 30 Nov 2026 18:40:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <11ekfu0$mq5n$4@dont-email.me>
References: <11bes8b$1gncr$1@dont-email.me>
	<11ek7b2$j8f6$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Nov 2026 18:40:01 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="747703"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+V8X7OSMdtYKZUbZzjIyBd"; posting-host="a13339aa161941cd02c77e7c540602f1"
User-Agent: Pan/0.165 (Kostiantynivka)
Cancel-Lock: sha1:363cnfbfmxZbq7j03BRUZr8EH3M= sha256:QEJkQq1jBw1mkexD9ChyxURBOIbwIBGOOQA+zg/qpmo=
	sha1:A1qzAvINZ5mw2w8q1qju7mBGwR0= sha256:NiZcFWXivWPYqNEIztZ0bycbLaSdQmxh1qh6EJfWZi8=