C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Let spaceship return an int

From: Chris Gary <cgary512_at_[hidden]>
Date: Wed, 27 Sep 2023 15:00:51 -0600
>
> And that goes back to my argument about combination.
>
> If it were just int for everything, then a combination of std::tuple of
> only
> fully-orderable types couldn't simply combine signs like Chris is
> suggesting
> could be optimal code. Instead, it would need to do actual value
> comparisons.
>

Type-safe composition of ordering can follow an intuitive definition.

For two structures, compare each pair of members in the declaration order,
apply common_type<> and take the first result that is not equal. Where one
structure is longer than the other, let common_type<T,void> -> T, then
invoke "T{} <=> value". Assuming plain bytes, the result is the same as a
memcmp with zero-padded arguments.

While an enum is supposed to represent a contract and combine accordingly,
it really can't. Robust code has to have a path assuming that, like any
other function, it can produce incorrect results, or a way to debug the
thing. It can't guarantee that the ordering is implemented correctly, and
that we have this extra thing called "unordered" instead of
"something_broke".

On Wed, Sep 27, 2023 at 9:05 AM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Wednesday, 27 September 2023 03:33:11 PDT Gašper Ažman via
> Std-Proposals
> wrote:
> > That's the design, and if you bring "int" into it you're basically
> > implicitly saying int maps to partial order, which is the most useless
> and
> > barely ever the right choice.
>
> And that goes back to my argument about combination.
>
> If it were just int for everything, then a combination of std::tuple of
> only
> fully-orderable types couldn't simply combine signs like Chris is
> suggesting
> could be optimal code. Instead, it would need to do actual value
> comparisons.
>
> Example:
> https://gcc.godbolt.org/z/jcqas5eYr
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel DCAI Cloud Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-09-27 21:01:03