public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "wjwray at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/93480] Defaulted <=> doesn't expand array elements Date: Fri, 18 Dec 2020 19:28:56 +0000 [thread overview] Message-ID: <bug-93480-4-aJv8QncFFG@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-93480-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480 Will Wray <wjwray at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wjwray at gmail dot com --- Comment #1 from Will Wray <wjwray at gmail dot com> --- I'm keen to see this fixed (and open to contribute) (defaulted array comparison now works on Clang & MSVC). Workaround for lack of compiler-generated array<=>array is awkward and brittle: https://godbolt.org/z/xr668E * Preprocessor conditional compilation is required (at least there seems no way to detect array<=>array support and dispatch to a user-defined comparison only as needed - iff array members are present): # if ! defined(__GNUC__) || defined(__clang__) auto operator<=>(C const&) const = default; # else constexpr auto operator<=>(C const& r) const { return three_way_compare(x,r.x); } #endif Then: * A generic 3-way comparison for array should be recursive. * Achieving efficient/vector codegen is not straightforward. * Deducing the return type is subtle: template <typename E, int N> constexpr auto three_way_compare(E const(&l)[N], E const(&r)[N]) { auto c = l[0] <=> r[0]; for (int i = 0; ++i != N; c = l[i] <=> r[i]) if (c != 0) return c; return c; } So it'd be better for all if this were compiler-generated.
next parent reply other threads:[~2020-12-18 19:28 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-93480-4@http.gcc.gnu.org/bugzilla/> 2020-12-18 19:28 ` wjwray at gmail dot com [this message] 2020-12-19 22:17 ` wjwray at gmail dot com 2020-12-20 14:23 ` jakub at gcc dot gnu.org 2020-12-21 22:49 ` wjwray at gmail dot com 2020-12-22 19:19 ` cvs-commit at gcc dot gnu.org 2020-12-22 19:19 ` jakub at gcc dot gnu.org 2021-01-18 15:18 ` ppalka at gcc dot gnu.org 2021-04-22 19:32 ` ppalka at gcc dot gnu.org 2022-12-26 17:50 ` pinskia at gcc dot gnu.org 2022-12-26 17:51 ` rhalbersma at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-93480-4-aJv8QncFFG@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).