From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1FD9D3844040 for ; Mon, 15 Apr 2024 18:30:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FD9D3844040 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1FD9D3844040 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713205802; cv=none; b=W1m7jrawIc4NoLJ3Qq18MhGt/48TfpSQES2ObjQ92iBmp+U0qS7wkvKcW2XnNIDQ2yK8iHr+AKqAWuiGEdM05CvQPoo2M0nAI5sgzggN2UBBURPuZDMh6EcmIlcAMtrjv2zAL9gqwwddB0YZyunArOOWJmPO30XymBTdinbuNS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713205802; c=relaxed/simple; bh=W51WoUedqMHxWnzaYHv2TAzKkkXLVBb21aizCEcevwk=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=itTcTCDJgxK8MQebpx1cFTElJjAOOSoXYf28nvIQgU1FZAdyyHAAb8niiN3yyuZOQ/Y6ysE0Dc2ryj500xjmDN3tl9i7EhCUz1nIroCGhIVt702Wv5GEEZJFqdozWJ+V11Bo0Nnorpz/tlDJq8rZT9eZ2E7HCMeATYdQtNl3ycI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713205800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sE/XcM5XFLhWQ4Bnh3em5pLzRvTj9RPf6yQVtem39Hw=; b=cvhJwsZKikPuxEANvh/lvchD6N5YlLmWIMVbvAk2SnYvemFEzUZ4uxR4rThR9Xxho8c+hj zU5UJ+ULHONcpk1YV7Gk9MbqPx/TkjCgibyre0KcxmfVUHOuscBuF9F4ChVs8/6pc1Zgl9 +mDtsWN8LwY7RMloyUIySSEzYKkuIYM= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-E4uI0zoaOZuU7E2IDByZmA-1; Mon, 15 Apr 2024 14:29:59 -0400 X-MC-Unique: E4uI0zoaOZuU7E2IDByZmA-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-61814249649so59351697b3.3 for ; Mon, 15 Apr 2024 11:29:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713205798; x=1713810598; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sE/XcM5XFLhWQ4Bnh3em5pLzRvTj9RPf6yQVtem39Hw=; b=XRc3sjZ+jw94lbovB74yQeBDFfTo/80LVYmqyMjwB+oBF+2i7mv1kIAX/kytYggdyK sm4lczPdwzlvefSjdtYFoORK8NDnzJIB6sP3EEMUbJu4rCq5eE+0UOqZsDeyQ3JAfFIO JGxu3jTv1nmOK9qLWJVDGLp+L6MhHgZcM13LunaI9aoM2MArOCYUZ6KX++O23FeX7hKm vGdRJ9954L9goP6HHHKicHRFpEORjBQHLmYIyloE6pwL8kw6uVRxZ+H2ko13iANn6YWq 3qn0i0+1xnqcONcS6KUKjxY80AenyDLio2MPTWGDsxN6WwBSqqyE0gDsuxw5ETlNCoqr aUXw== X-Gm-Message-State: AOJu0YxcElQQoz6naGtA7UkwCSGRGM/B9Y/WGN4uS3Cj/VEyDUUgNub/ 9ppO3JRWVb1f0IUqZTU3soKWaeyv19U7ejVgBzBtgDemj4R0l3vOAu1D4Nws8wy3WuFFnOL4eZD KgybLtHhpbxoLQdg6dG+i7cqoUQUKDMrX75/uu+3v+I79qGRCf8vOIM7BZzCV6Vvx4hvV3Ul/tV uvU7Im2AfnjS8Ze82GjQSTT66+3K4Msb2bQQQ= X-Received: by 2002:a05:6902:728:b0:dcc:323e:e1a4 with SMTP id l8-20020a056902072800b00dcc323ee1a4mr12310158ybt.6.1713205798522; Mon, 15 Apr 2024 11:29:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGa88xg5/nucS0XWCBaNam/pmS/xXzqa1fYLtYie56AKJ2DYQZkQaPvRRef5lqdemMjxYeQeX1xCXeTzgppYB8= X-Received: by 2002:a05:6902:728:b0:dcc:323e:e1a4 with SMTP id l8-20020a056902072800b00dcc323ee1a4mr12310142ybt.6.1713205798179; Mon, 15 Apr 2024 11:29:58 -0700 (PDT) MIME-Version: 1.0 References: <20240410085039.267589-1-jwakely@redhat.com> In-Reply-To: <20240410085039.267589-1-jwakely@redhat.com> From: Jonathan Wakely Date: Mon, 15 Apr 2024 19:29:42 +0100 Message-ID: Subject: Re: [PATCH 1/4] libstdc++: Heterogeneous std::pair comparisons [PR113386] To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-15.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Pushed to trunk now. On Wed, 10 Apr 2024 at 09:51, Jonathan Wakely wrote: > > Tested x86_64-linux. > > Since this only affects C++20 and later it seems OK for trunk now. > > -- >8 -- > > I'm only treating this as a DR for C++20 for now, because it's less work > and only requires changes to operator== and operator<=>. To do this for > older standards would require changes to the six relational operators > used pre-C++20. > > libstdc++-v3/ChangeLog: > > PR libstdc++/113386 > * include/bits/stl_pair.h (operator==, operator<=>): Support > heterogeneous comparisons, as per LWG 3865. > * testsuite/20_util/pair/comparison_operators/lwg3865.cc: New > test. > --- > libstdc++-v3/include/bits/stl_pair.h | 32 ++++++++++++++----- > .../pair/comparison_operators/lwg3865.cc | 15 +++++++++ > 2 files changed, 39 insertions(+), 8 deletions(-) > create mode 100644 libstdc++-v3/testsuite/20_util/pair/comparison_operators/lwg3865.cc > > diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h > index 4f5c8389fa6..45317417c9c 100644 > --- a/libstdc++-v3/include/bits/stl_pair.h > +++ b/libstdc++-v3/include/bits/stl_pair.h > @@ -1000,23 +1000,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > template pair(_T1, _T2) -> pair<_T1, _T2>; > #endif > > - /// Two pairs of the same type are equal iff their members are equal. > - template > +#if __cpp_lib_three_way_comparison && __cpp_lib_concepts > + // _GLIBCXX_RESOLVE_LIB_DEFECTS > + // 3865. Sorting a range of pairs > + > + /// Two pairs are equal iff their members are equal. > + template > inline _GLIBCXX_CONSTEXPR bool > - operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) > + operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) > { return __x.first == __y.first && __x.second == __y.second; } > > -#if __cpp_lib_three_way_comparison && __cpp_lib_concepts > - template > - constexpr common_comparison_category_t<__detail::__synth3way_t<_T1>, > - __detail::__synth3way_t<_T2>> > - operator<=>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) > + /** Defines a lexicographical order for pairs. > + * > + * For two pairs of comparable types, `P` is ordered before `Q` if > + * `P.first` is less than `Q.first`, or if `P.first` and `Q.first` > + * are equivalent (neither is less than the other) and `P.second` is > + * less than `Q.second`. > + */ > + template > + constexpr common_comparison_category_t<__detail::__synth3way_t<_T1, _U1>, > + __detail::__synth3way_t<_T2, _U2>> > + operator<=>(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) > { > if (auto __c = __detail::__synth3way(__x.first, __y.first); __c != 0) > return __c; > return __detail::__synth3way(__x.second, __y.second); > } > #else > + /// Two pairs of the same type are equal iff their members are equal. > + template > + inline _GLIBCXX_CONSTEXPR bool > + operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) > + { return __x.first == __y.first && __x.second == __y.second; } > + > /** Defines a lexicographical order for pairs. > * > * For two pairs of the same type, `P` is ordered before `Q` if > diff --git a/libstdc++-v3/testsuite/20_util/pair/comparison_operators/lwg3865.cc b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/lwg3865.cc > new file mode 100644 > index 00000000000..2bbd54af192 > --- /dev/null > +++ b/libstdc++-v3/testsuite/20_util/pair/comparison_operators/lwg3865.cc > @@ -0,0 +1,15 @@ > +// { dg-do run { target c++20 } } > + > +// LWG 3865. Sorting a range of pairs > + > +#include > +#include > + > +int main() > +{ > + std::pair p(1, 2); > + std::pair p2(p.first, p.second); > + VERIFY( p == p2 ); > + VERIFY( p <= p2 ); > + VERIFY( p >= p2 ); > +} > -- > 2.44.0 >