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: Sat, 19 Dec 2020 22:17:29 +0000 [thread overview] Message-ID: <bug-93480-4-kBOIiaS8df@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 --- Comment #2 from Will Wray <wjwray at gmail dot com> --- For reference, here's a macro-free workaround to provide portable operator<=> for templated classes with array members, defaulting where possible (current Clang and MSVC) otherwise dispatching to a user-defined implementation (current gcc) https://godbolt.org/z/qbEfh7 First, a trait to check default 3-way array compare: inline constexpr bool has_default_array_compare = [] { struct C { char c[1]; auto operator<=>(C const&) const = default; }; return std::three_way_comparable<C>; }(); Then constrain the operator<=> definitions template <typename T, int N> struct array { T data[N]; friend auto operator<=>(array const&, array const&) requires has_default_array_compare = default; friend constexpr auto operator<=>(array const& l, array const& r) requires (!has_default_array_compare) { return compare_three_way{}(l.data,r.data); } }; However, this only works for templated classes as it is not (yet) allowed to constrain non-template functions.
next prev parent reply other threads:[~2020-12-19 22:17 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 2020-12-19 22:17 ` wjwray at gmail dot com [this message] 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-kBOIiaS8df@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).