From patchwork Tue Aug 23 01:34:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp747492wro; Mon, 22 Aug 2022 18:37:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR6XO6IIgtY0LUaZcnpaGseJPPGTZ3Z5Uk+Vor23Lc3f2XPPIMg6Iz431IWQVVuIYLKoHNB5 X-Received: by 2002:a17:906:8467:b0:73d:8873:841b with SMTP id hx7-20020a170906846700b0073d8873841bmr3537265ejc.418.1661218629886; Mon, 22 Aug 2022 18:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661218629; cv=none; d=google.com; s=arc-20160816; b=Mv41H6iFrtiyZ4sF5vud5kGPpMj2oQvFjQGJb3YJlYMjO3MTh1iBSzovwjyXd+pDte orZtdyTs/catKRCN9qLpOouOc16Yphyk1Lii38n9d8Ats6Q4Nf7gh/xEhHPR1LbuQrvh UadWGdJbp6XYRqhz0Vv3U1tvqHbYZldzRpgMXj39rWNz5VIyo1SrFrvRvdWkRYc2veVB 7pZe4vW7zXq4Wmxc7Huq6KVyIk8Ly7UnUQmMHhPrEhI/vjKkU+atWrCEGMUo7dIGPVsf b5i7Bqr4PC3EDthEv/Q0uX6hmI3Ffp8s5cXDyVSAHTr33jn7rm2glc8NsrKMzYIL+rTS YgOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=AuINIqY5DB3JSAR7pGlThWQrz8bZqSMi4NmPZ/k0APc=; b=k/Y8g7f6VKeZkAeNdyhcletikStrDmOIWySUBTZi/zieQQcN6SKTvqQO16XCAOqadF R1Rat07+B8NvCMEOSwb7CzHonFmQdryPk5JV7dZCqiN4+3DAgic0YeKCb+J1BL06h6p1 m7hkYF9YbCUAxcdeIAOkju5hi8zbrr3uxzmwnZHAsdnoWqOYmFxFvB/us1R/IDDZYSfq 8K1p9xVvk3mEdgTgWS5shIggeIUyHiEbTQcm7YYRE9m6eL1kiS6Jv91Ripcdl/5VSPmS +iJ5DoDsnbPBrTWx+K/3QCoYadY6qwPoZ+sgsDo6rkK7GUOptTEP3xqR02sa/RNTwWTh Tf3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=K2V18Xz6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z21-20020a056402275500b00442edebe687si863883edd.633.2022.08.22.18.37.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 18:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=K2V18Xz6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09E3A3850230 for ; Tue, 23 Aug 2022 01:35:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09E3A3850230 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661218558; bh=AuINIqY5DB3JSAR7pGlThWQrz8bZqSMi4NmPZ/k0APc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=K2V18Xz6PBr4abN5kCg2MYp+1YPFf5unU8TQ3moTk7tZ2N+nbc8cnZGeeO7kz3/9s N6XY7cMkD//cVuJ+mYW5hW70GKFAWSwaC2FLEv7VBlmWfHi7gN+8CKUMHUDsQMsq2c EWHIHl7wySbmfp+sXA2vAQzUe3FjonMY+Gq1Lmgs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 45B593858C39 for ; Tue, 23 Aug 2022 01:35:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 45B593858C39 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-438-zsyjymXtNRmUL7bf3LEvMQ-1; Mon, 22 Aug 2022 21:35:07 -0400 X-MC-Unique: zsyjymXtNRmUL7bf3LEvMQ-1 Received: by mail-qt1-f199.google.com with SMTP id s2-20020ac85cc2000000b00342f8ad1f40so9561926qta.12 for ; Mon, 22 Aug 2022 18:35:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=AuINIqY5DB3JSAR7pGlThWQrz8bZqSMi4NmPZ/k0APc=; b=ruE1dC2G4rQRgpulMliruuwlcfxrTZan5UjO84Cac+5qyXDpsVxXVG1LxKc6jDq3b0 RZbRvrJ3kJlY5QMDHeOLYTS2+aO8O6zSbioHcsNRpLCr1nMKokcnVGN0iZiMxk5Pm2DI XENMeHd6sHoMfNZbF/FudB1bQXh9HtYHv/gJEJanfqFyK/nWPZx4iE2E86uEs1MCdhhg dCCzsad20EfnU2FPzWpPa1dYaBJzsEh176lcNgKW85gzHtv4I9yHieQcxFhZUwuZ3Ivy z8FpPW/uezwQknpBxUO+uY4ioM2U3GLbA26gFi0MlJImB9yYA+mtSSxn4u5pspNA9eSt Audw== X-Gm-Message-State: ACgBeo2NQC66XDDWyoqxnlBO0NkVN4YW8xzoXNwwY1sLPBVpi1D8rRP3 W9pJK6PucIoCeIVxj/QgMqrzUWh9qiLWP95Fy93s5JZmhLTAuw4UpKIJlS0YKdaWentL/OL07ap OFY/TcRNhR3zHzvpGYrYPAVQAsfpNvl1xi6uOsdO92TS9RZycHtiRGMvNKokhSWIkUHc= X-Received: by 2002:a37:b702:0:b0:6b8:d9ec:3196 with SMTP id h2-20020a37b702000000b006b8d9ec3196mr14215362qkf.660.1661218505718; Mon, 22 Aug 2022 18:35:05 -0700 (PDT) X-Received: by 2002:a37:b702:0:b0:6b8:d9ec:3196 with SMTP id h2-20020a37b702000000b006b8d9ec3196mr14215335qkf.660.1661218504676; Mon, 22 Aug 2022 18:35:04 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id p11-20020ac8740b000000b00342fcdc2d46sm9816942qtq.56.2022.08.22.18.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 18:35:04 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] libstdc++: Implement std::pair/tuple/misc enhancements from P2321R2 Date: Mon, 22 Aug 2022 21:34:59 -0400 Message-Id: <20220823013500.1756466-2-ppalka@redhat.com> X-Mailer: git-send-email 2.37.2.382.g795ea8776b In-Reply-To: <20220823013500.1756466-1-ppalka@redhat.com> References: <20220823013500.1756466-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741913986126580084?= X-GMAIL-MSGID: =?utf-8?q?1741913986126580084?= This implements the non- changes from P2321R2, which primarily consist of new converting constructors, assignment operator and swap overloads for std::pair and std::tuple. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/bits/stl_bvector.h (_Bit_reference::operator=): Define const overload for C++23 as per P2321R2. * include/bits/stl_pair.h (pair::swap): Likewise. (pair::pair): Define additional converting constructors for C++23 as per P2321R2. (pair::operator=): Define const overloads for C++23 as per P2321R2. (swap): Define overload taking const pair& for C++23 as per P2321R2. (basic_common_reference): Define partial specialization for pair for C++23 as per P2321R2. (common_type): Likewise. * include/bits/uses_allocator_args.h (uses_allocator_construction_args): Define additional pair overloads for C++23 as per P2321R2. * include/std/tuple (_Tuple_impl::_Tuple_impl): Define additional converting constructors for C++23 as per P2321R2. (_Tuple_impl::_M_assign): Define const overloads for C++23 as per P2321R2. (_Tuple_impl::_M_swap): Likewise. (tuple::__constructible): Define as a convenient renaming of _TCC::__constructible. (tuple::__convertible): As above but for _TCC::__convertible. (tuple::tuple): Define additional converting constructors for C++23 as per P2321R2. (tuple::operator=): Define const overloads for C++23 as per P2321R2. (tuple::swap): Likewise. (basic_common_reference): Define partial specialization for tuple for C++23 as per P2321R2. (common_type): Likewise. * testsuite/20_util/pair/p2321.cc: New test. * testsuite/20_util/tuple/p2321.cc: New test. * testsuite/23_containers/vector/bool/element_access/1.cc: New test. --- libstdc++-v3/include/bits/stl_bvector.h | 12 + libstdc++-v3/include/bits/stl_pair.h | 118 +++- .../include/bits/uses_allocator_args.h | 41 ++ libstdc++-v3/include/std/tuple | 416 +++++++++++ libstdc++-v3/testsuite/20_util/pair/p2321.cc | 208 ++++++ libstdc++-v3/testsuite/20_util/tuple/p2321.cc | 664 ++++++++++++++++++ .../vector/bool/element_access/1.cc | 26 + 7 files changed, 1480 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/pair/p2321.cc create mode 100644 libstdc++-v3/testsuite/20_util/tuple/p2321.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index d256af40f40..c5fd19e7309 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -106,6 +106,18 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return *this; } +#if __cplusplus > 202002L + constexpr const _Bit_reference& + operator=(bool __x) const noexcept + { + if (__x) + *_M_p |= _M_mask; + else + *_M_p &= ~_M_mask; + return *this; + } +#endif + _GLIBCXX20_CONSTEXPR _Bit_reference& operator=(const _Bit_reference& __x) _GLIBCXX_NOEXCEPT diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h index 831e770d54b..d0efba635bc 100644 --- a/libstdc++-v3/include/bits/stl_pair.h +++ b/libstdc++-v3/include/bits/stl_pair.h @@ -212,6 +212,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION swap(second, __p.second); } +#if __cplusplus > 202002L + /// Swap the first members and then the second members. + constexpr void + swap(const pair& __p) const + noexcept(__and_<__is_nothrow_swappable, + __is_nothrow_swappable>::value) + { + using std::swap; + swap(first, __p.first); + swap(second, __p.second); + } +#endif // C++23 + private: template @@ -283,7 +296,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { } - /// Converting constructor from a `pair` lvalue + /// Converting constructor from a const `pair` lvalue template requires (_S_constructible()) constexpr explicit(!_S_convertible()) @@ -292,7 +305,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : first(__p.first), second(__p.second) { } - /// Converting constructor from a `pair` rvalue + /// Converting constructor from a non-const `pair` rvalue template requires (_S_constructible<_U1, _U2>()) constexpr explicit(!_S_convertible<_U1, _U2>()) @@ -302,6 +315,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION second(std::forward<_U2>(__p.second)) { } +#if __cplusplus > 202002L + /// Converting constructor from a non-const `pair` lvalue + template + requires (_S_constructible<_U1&, _U2&>()) + constexpr explicit(!_S_convertible<_U1&, _U2&>()) + pair(pair<_U1, _U2>& __p) + noexcept(_S_nothrow_constructible<_U1&, _U2&>()) + : first(__p.first), second(__p.second) + { } + + /// Converting constructor from a const `pair` rvalue + template + requires (_S_constructible()) + constexpr explicit(!_S_convertible()) + pair(const pair<_U1, _U2>&& __p) + noexcept(_S_nothrow_constructible()) + : first(std::forward(__p.first)), + second(std::forward(__p.second)) + { } +#endif + private: /// @cond undocumented template @@ -349,7 +383,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } - /// Converting assignment from a `pair` lvalue + /// Converting assignment from a const `pair` lvalue template constexpr pair& operator=(const pair<_U1, _U2>& __p) @@ -361,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } - /// Converting assignment from a `pair` rvalue + /// Converting assignment from a non-const `pair` rvalue template constexpr pair& operator=(pair<_U1, _U2>&& __p) @@ -372,7 +406,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION second = std::forward<_U2>(__p.second); return *this; } -#else + +#if __cplusplus > 202002L + /// Copy assignment operator + constexpr const pair& + operator=(const pair& __p) const + requires is_copy_assignable_v + && is_copy_assignable_v + { + first = __p.first; + second = __p.second; + return *this; + } + + /// Move assignment operator + constexpr const pair& + operator=(pair&& __p) const + requires is_assignable_v + && is_assignable_v + { + first = std::forward(__p.first); + second = std::forward(__p.second); + return *this; + } + + /// Converting assignment from a const `pair` lvalue + template + constexpr const pair& + operator=(const pair<_U1, _U2>& __p) const + requires is_assignable_v + && is_assignable_v + { + first = __p.first; + second = __p.second; + return *this; + } + + /// Converting assignment from a non-const `pair` rvalue + template + constexpr const pair& + operator=(pair<_U1, _U2>&& __p) const + requires is_assignable_v + && is_assignable_v + { + first = std::forward<_U1>(__p.first); + second = std::forward<_U2>(__p.second); + return *this; + } +#endif // C++23 +#else // !__cpp_lib_concepts // C++11/14/17 implementation using enable_if, partially constexpr. /** The default constructor creates @c first and @c second using their @@ -710,6 +792,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } +#if __cplusplus > 202002L + template + requires is_swappable::value && is_swappable::value + constexpr void + swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) + noexcept(noexcept(__x.swap(__y))) + { __x.swap(__y); } +#endif // C++23 + #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 template typename enable_if, @@ -918,6 +1009,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION get(const pair<_Up, _Tp>&& __p) noexcept { return std::move(__p.second); } +#if __cplusplus > 202002L + template class _TQual, template class _UQual> + requires requires { typename pair, _UQual<_U1>>, + common_reference_t<_TQual<_T2>, _UQual<_U2>>>; } + struct basic_common_reference, pair<_U1, _U2>, _TQual, _UQual> + { + using type = pair, _UQual<_U1>>, + common_reference_t<_TQual<_T2>, _UQual<_U2>>>; + }; + + template + requires requires { typename pair, common_type_t<_T2, _U2>>; } + struct common_type, pair<_U1, _U2>> + { using type = pair, common_type_t<_T2, _U2>>; }; +#endif + #endif // C++14 /// @} #endif // C++11 diff --git a/libstdc++-v3/include/bits/uses_allocator_args.h b/libstdc++-v3/include/bits/uses_allocator_args.h index 09cdbf1aaa8..3528e4cc4fa 100644 --- a/libstdc++-v3/include/bits/uses_allocator_args.h +++ b/libstdc++-v3/include/bits/uses_allocator_args.h @@ -107,6 +107,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr auto uses_allocator_construction_args(const _Alloc&, pair<_Up, _Vp>&&) noexcept; +#if __cplusplus > 202002L + template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp> + constexpr auto + uses_allocator_construction_args(const _Alloc&, + pair<_Up, _Vp>&) noexcept; + + template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp> + constexpr auto + uses_allocator_construction_args(const _Alloc&, const pair<_Up, _Vp>&&) noexcept; +#endif + template<_Std_pair _Tp, typename _Alloc, typename _Tuple1, typename _Tuple2> constexpr auto uses_allocator_construction_args(const _Alloc& __a, piecewise_construct_t, @@ -181,6 +192,36 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::move(__pr).second)); } +#if __cplusplus > 202002L + template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp> + constexpr auto + uses_allocator_construction_args(const _Alloc& __a, + pair<_Up, _Vp>& __pr) noexcept + { + using _Tp1 = typename _Tp::first_type; + using _Tp2 = typename _Tp::second_type; + + return std::make_tuple(piecewise_construct, + std::uses_allocator_construction_args<_Tp1>(__a, __pr.first), + std::uses_allocator_construction_args<_Tp2>(__a, __pr.second)); + } + + template<_Std_pair _Tp, typename _Alloc, typename _Up, typename _Vp> + constexpr auto + uses_allocator_construction_args(const _Alloc& __a, + const pair<_Up, _Vp>&& __pr) noexcept + { + using _Tp1 = typename _Tp::first_type; + using _Tp2 = typename _Tp::second_type; + + return std::make_tuple(piecewise_construct, + std::uses_allocator_construction_args<_Tp1>(__a, + std::move(__pr).first), + std::uses_allocator_construction_args<_Tp2>(__a, + std::move(__pr).second)); + } +#endif + template constexpr _Tp make_obj_using_allocator(const _Alloc& __a, _Args&&... __args) diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple index d0c168fd7e2..812e70d17be 100644 --- a/libstdc++-v3/include/std/tuple +++ b/libstdc++-v3/include/std/tuple @@ -316,6 +316,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { } +#if __cplusplus > 202002L + template + constexpr + _Tuple_impl(_Tuple_impl<_Idx, _UElements...>& __in) + : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)), + _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) + { } + + template + constexpr + _Tuple_impl(const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in) + : _Inherited(std::move + (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))), + _Base(std::forward + (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) + { } +#endif + template _GLIBCXX20_CONSTEXPR _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a) @@ -379,6 +397,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { } +#if __cplusplus > 202002L + template + constexpr + _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, + _Tuple_impl<_Idx, _UHead, _UTails...>& __in) + : _Inherited(__tag, __a, + _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)), + _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a), + _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)) + { } + + template + constexpr + _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, + const _Tuple_impl<_Idx, _UHead, _UTails...>&& __in) + : _Inherited(__tag, __a, std::move + (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))), + _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a), + std::forward + (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) + { } +#endif + template _GLIBCXX20_CONSTEXPR void @@ -400,6 +441,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))); } +#if __cplusplus > 202002L + template + constexpr void + _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in) const + { + _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in); + _M_tail(*this)._M_assign( + _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)); + } + + template + constexpr void + _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in) const + { + _M_head(*this) = std::forward<_UHead> + (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)); + _M_tail(*this)._M_assign( + std::move(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))); + } +#endif + protected: _GLIBCXX20_CONSTEXPR void @@ -409,6 +471,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION swap(_M_head(*this), _M_head(__in)); _Inherited::_M_swap(_M_tail(__in)); } + +#if __cplusplus > 202002L + constexpr void + _M_swap(const _Tuple_impl& __in) const + { + using std::swap; + swap(_M_head(*this), _M_head(__in)); + _Inherited::_M_swap(_M_tail(__in)); + } +#endif }; // Basis case of inheritance recursion. @@ -469,6 +541,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) { } +#if __cplusplus > 202002L + template + constexpr + _Tuple_impl(_Tuple_impl<_Idx, _UHead>& __in) + : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) + { } + + template + constexpr + _Tuple_impl(const _Tuple_impl<_Idx, _UHead>&& __in) + : _Base(std::forward(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) + { } +#endif + template _GLIBCXX20_CONSTEXPR _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a) @@ -521,6 +607,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) { } +#if __cplusplus > 202002L + template + constexpr + _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, + _Tuple_impl<_Idx, _UHead>& __in) + : _Base(__use_alloc<_Head, _Alloc, _UHead&>(__a), + _Tuple_impl<_Idx, _UHead>::_M_head(__in)) + { } + + template + constexpr + _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a, + const _Tuple_impl<_Idx, _UHead>&& __in) + : _Base(__use_alloc<_Head, _Alloc, const _UHead>(__a), + std::forward(_Tuple_impl<_Idx, _UHead>::_M_head(__in))) + { } +#endif + template _GLIBCXX20_CONSTEXPR void @@ -538,6 +642,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)); } +#if __cplusplus > 202002L + template + constexpr void + _M_assign(const _Tuple_impl<_Idx, _UHead>& __in) const + { + _M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in); + } + + template + constexpr void + _M_assign(_Tuple_impl<_Idx, _UHead>&& __in) const + { + _M_head(*this) + = std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)); + } +#endif + protected: _GLIBCXX20_CONSTEXPR void @@ -546,6 +667,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using std::swap; swap(_M_head(*this), _M_head(__in)); } + +#if __cplusplus > 202002L + constexpr void + _M_swap(const _Tuple_impl& __in) const + { + using std::swap; + swap(_M_head(*this), _M_head(__in)); + } +#endif }; // Concept utility functions, reused in conditionally-explicit @@ -728,6 +858,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr bool __use_other_ctor() { return _UseOtherCtor<_Tuple>::value; } +#if __cplusplus > 202002L + template + static constexpr bool __constructible + = _TCC::template __constructible<_Args...>; + + template + static constexpr bool __convertible + = _TCC::template __convertible<_Args...>; +#endif + public: template::value> = true> @@ -815,6 +955,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(__nothrow_constructible<_UElements...>()) : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { } +#if __cplusplus > 202002L + template + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (!__use_other_ctor&>()) + && __constructible<_UElements&...> + explicit(!__convertible<_UElements&...>) + constexpr + tuple(tuple<_UElements...>& __in) + noexcept(__nothrow_constructible<_UElements&...>()) + : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&>(__in)) + { } + + template + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (!__use_other_ctor&&>()) + && __constructible + explicit(!__convertible) + constexpr + tuple(const tuple<_UElements...>&& __in) + noexcept(__nothrow_constructible()) + : _Inherited(static_cast&&>(__in)) { } +#endif + // Allocator-extended constructors. template&&>(__in)) { } +#if __cplusplus > 202002L + template + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (!__use_other_ctor&>()) + && __constructible<_UElements&...> + explicit(!__convertible<_UElements&...>) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, + tuple<_UElements...>& __in) + : _Inherited(__tag, __a, + static_cast<_Tuple_impl<0, _UElements...>&>(__in)) + { } + + template + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (!__use_other_ctor>()) + && __constructible + explicit(!__convertible) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, + const tuple<_UElements...>&& __in) + : _Inherited(__tag, __a, + static_cast&&>(__in)) + { } +#endif + // tuple assignment _GLIBCXX20_CONSTEXPR @@ -957,12 +1146,57 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } +#if __cplusplus > 202002L + constexpr const tuple& + operator=(const tuple& __in) const + requires (is_copy_assignable_v && ...) + { + this->_M_assign(__in); + return *this; + } + + constexpr const tuple& + operator=(tuple&& __in) const + requires (is_assignable_v && ...) + { + this->_M_assign(std::move(__in)); + return *this; + } + + template + constexpr const tuple& + operator=(const tuple<_UElements...>& __in) const + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (is_assignable_v && ...) + { + this->_M_assign(__in); + return *this; + } + + template + constexpr const tuple& + operator=(tuple<_UElements...>&& __in) const + requires (sizeof...(_Elements) == sizeof...(_UElements)) + && (is_assignable_v && ...) + { + this->_M_assign(std::move(__in)); + return *this; + } +#endif + // tuple swap _GLIBCXX20_CONSTEXPR void swap(tuple& __in) noexcept(__and_<__is_nothrow_swappable<_Elements>...>::value) { _Inherited::_M_swap(__in); } + +#if __cplusplus > 202002L + constexpr void + swap(const tuple& __in) const + noexcept(__and_<__is_nothrow_swappable...>::value) + { _Inherited::_M_swap(__in); } +#endif }; #if __cpp_deduction_guides >= 201606 @@ -985,6 +1219,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: _GLIBCXX20_CONSTEXPR void swap(tuple&) noexcept { /* no-op */ } +#if __cplusplus > 202002L + constexpr void swap(const tuple&) const noexcept { /* no-op */ } +#endif // We need the default since we're going to define no-op // allocator constructors. tuple() = default; @@ -1064,6 +1301,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr bool __is_alloc_arg() { return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; } +#if __cplusplus > 202002L + template + static constexpr bool __constructible + = _TCC::template __constructible<_U1, _U2>; + + template + static constexpr bool __convertible + = _TCC::template __convertible<_U1, _U2>; +#endif + public: template = true> @@ -1139,6 +1386,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(__nothrow_constructible<_U1, _U2>()) : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { } +#if __cplusplus > 202002L + template + requires __constructible<_U1&, _U2&> + explicit(!__convertible<_U1&, _U2&>) + constexpr + tuple(tuple<_U1, _U2>& __in) + noexcept(__nothrow_constructible<_U1&, _U2&>()) + : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&>(__in)) { } + + template + requires __constructible + explicit(!__convertible) + constexpr + tuple(const tuple<_U1, _U2>&& __in) + noexcept(__nothrow_constructible()) + : _Inherited(static_cast&&>(__in)) { } +#endif + template = true> constexpr @@ -1169,6 +1434,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(std::forward<_U1>(__in.first), std::forward<_U2>(__in.second)) { } +#if __cplusplus > 202002L + template + requires __constructible<_U1&, _U2&> + explicit(!__convertible<_U1&, _U2&>) + constexpr + tuple(pair<_U1, _U2>& __in) + noexcept(__nothrow_constructible<_U1&, _U2&>()) + : _Inherited(__in.first, __in.second) { } + + template + requires __constructible + explicit(!__convertible) + constexpr + tuple(const pair<_U1, _U2>&& __in) + noexcept(__nothrow_constructible()) + : _Inherited(std::forward(__in.first), + std::forward(__in.second)) { } +#endif + // Allocator-extended constructors. template&&>(__in)) { } +#if __cplusplus > 202002L + template + requires __constructible<_U1&, _U2&> + explicit(!__convertible<_U1&, _U2&>) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, + tuple<_U1, _U2>& __in) + : _Inherited(__tag, __a, + static_cast<_Tuple_impl<0, _U1, _U2>&>(__in)) + { } + + template + requires __constructible + explicit(!__convertible) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, + const tuple<_U1, _U2>&& __in) + : _Inherited(__tag, __a, + static_cast&&>(__in)) + { } +#endif + template = true> _GLIBCXX20_CONSTEXPR @@ -1282,6 +1588,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : _Inherited(__tag, __a, std::forward<_U1>(__in.first), std::forward<_U2>(__in.second)) { } +#if __cplusplus > 202002L + template + requires __constructible<_U1&, _U2&> + explicit(!__convertible<_U1&, _U2&>) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, + pair<_U1, _U2>& __in) + : _Inherited(__tag, __a, __in.first, __in.second) { } + + template + requires __constructible + explicit(!__convertible) + constexpr + tuple(allocator_arg_t __tag, const _Alloc& __a, const pair<_U1, _U2>&& __in) + : _Inherited(__tag, __a, std::forward(__in.first), + std::forward(__in.second)) { } +#endif + // Tuple assignment. _GLIBCXX20_CONSTEXPR @@ -1326,6 +1650,44 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } +#if __cplusplus > 202002L + constexpr const tuple& + operator=(const tuple& __in) const + requires is_copy_assignable_v && is_copy_assignable_v + { + this->_M_assign(__in); + return *this; + } + + constexpr const tuple& + operator=(tuple&& __in) const + requires is_assignable_v && is_assignable_v + { + this->_M_assign(std::move(__in)); + return *this; + } + + template + constexpr const tuple& + operator=(const tuple<_U1, _U2>& __in) const + requires is_assignable_v + && is_assignable_v + { + this->_M_assign(__in); + return *this; + } + + template + constexpr const tuple& + operator=(tuple<_U1, _U2>&& __in) const + requires is_assignable_v + && is_assignable_v + { + this->_M_assign(std::move(__in)); + return *this; + } +#endif + template _GLIBCXX20_CONSTEXPR __enable_if_t<__assignable(), tuple&> @@ -1348,12 +1710,44 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return *this; } +#if __cplusplus > 202002L + template + constexpr const tuple& + operator=(const pair<_U1, _U2>& __in) const + requires is_assignable_v + && is_assignable_v + { + this->_M_head(*this) = __in.first; + this->_M_tail(*this)._M_head(*this) = __in.second; + return *this; + } + + template + constexpr const tuple& + operator=(pair<_U1, _U2>&& __in) const + requires is_assignable_v + && is_assignable_v + { + this->_M_head(*this) = std::forward<_U1>(__in.first); + this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second); + return *this; + } +#endif + _GLIBCXX20_CONSTEXPR void swap(tuple& __in) noexcept(__and_<__is_nothrow_swappable<_T1>, __is_nothrow_swappable<_T2>>::value) { _Inherited::_M_swap(__in); } + +#if __cplusplus > 202002L + constexpr void + swap(const tuple& __in) const + noexcept(__and_<__is_nothrow_swappable, + __is_nothrow_swappable>::value) + { _Inherited::_M_swap(__in); } +#endif }; @@ -1781,6 +2175,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION noexcept(noexcept(__x.swap(__y))) { __x.swap(__y); } +#if __cplusplus > 202002L + template + requires (__is_swappable::value && ...) + constexpr void + swap(const tuple<_Elements...>& __x, const tuple<_Elements...>& __y) + noexcept(noexcept(__x.swap(__y))) + { __x.swap(__y); } +#endif + #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 template _GLIBCXX20_CONSTEXPR @@ -1905,6 +2308,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif // C++17 +#if __cplusplus > 202002L + template class TQual, template class UQual> + requires requires { typename tuple, UQual<_UTypes>>...>; } + struct basic_common_reference, tuple<_UTypes...>, TQual, UQual> + { using type = tuple, UQual<_UTypes>>...>; }; + + template + requires requires { typename tuple...>; } + struct common_type, tuple<_UTypes...>> + { using type = tuple...>; }; +#endif + /// @} _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/20_util/pair/p2321.cc b/libstdc++-v3/testsuite/20_util/pair/p2321.cc new file mode 100644 index 00000000000..4f436ee03d6 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/pair/p2321.cc @@ -0,0 +1,208 @@ +// Verify P2321R2 "zip" enhancements to std::pair. +// { dg-options "-std=gnu++23" } +// { dg-do run { target c++23 } } + +#include +#include + +using std::pair; + +struct A { }; + +constexpr bool +test01() +{ + struct B { bool v; constexpr B(A&) : v(true) { } }; + + // template + // constexpr explicit(false) pair(pair&); + + pair p2a0; + pair p2b0 = p2a0; + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + pair p2b1 = p2a1; + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +constexpr bool +test02() +{ + struct B { bool v; explicit constexpr B(A&) : v(true) { } }; + + // template + // constexpr explicit(true) pair(pair&); + + static_assert(!std::is_convertible_v&, pair>); + static_assert(!std::is_convertible_v&, pair>); + + pair p2a0; + pair p2b0(p2a0); + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + pair p2b1(p2a1); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +constexpr bool +test03() +{ + struct B { bool v; constexpr B(const A&&) : v(true) { } }; + + // template + // constexpr explicit(false) pair(const pair&&); + + const pair p2a0; + pair p2b0 = std::move(p2a0); + VERIFY( std::get<0>(p2b0).v ); + + const pair p2a1; + pair p2b1 = std::move(p2a1); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +constexpr bool +test04() +{ + struct B { bool v; explicit constexpr B(const A&&) : v(true) { } }; + + // template + // constexpr explicit(true) pair(const pair&&); + + static_assert(!std::is_convertible_v&&, pair>); + static_assert(!std::is_convertible_v&&, pair>); + + const pair p2a0; + pair p2b0(std::move(p2a0)); + VERIFY( std::get<0>(p2b0).v ); + + const pair p2a1; + pair p2b1(std::move(p2a1)); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +constexpr bool +test05() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(const A&) const { v = true; return *this; } + }; + + // template + // constexpr const pair& operator=(const pair&) const; + + const pair p2a; + const pair p2b; + p2b = p2a; + + return true; +} + +constexpr bool +test06() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(A&&) const { v = true; return *this; } + }; + + // template + // constexpr const pair& operator=(pair&&) const; + + pair p2a; + const pair p2b; + p2b = std::move(p2a); + + return true; +} + +constexpr bool +test07() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(const B&) const { v = true; return *this; } + }; + + // constexpr const pair& operator=(const pair&) const; + + const pair t2a; + const pair t2b; + t2b = t2a; + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + return true; +} + +constexpr bool +test08() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(B&&) const { v = true; return *this; } + }; + + // constexpr const pair& operator=(pair&&) const; + + pair t2a; + const pair t2b; + t2b = std::move(t2a); + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + return true; +} + +struct S +{ + mutable int v = 0; + friend constexpr void swap(S&& x, S&& y) = delete; + friend constexpr void swap(const S& x, const S& y) { ++x.v; ++y.v; } +}; + +constexpr bool +test09() +{ + const pair t2, u2; + std::swap(t2, u2); + VERIFY( std::get<0>(t2).v == 1 ); + VERIFY( std::get<0>(u2).v == 1 ); + VERIFY( std::get<1>(t2).v == 1 ); + VERIFY( std::get<1>(u2).v == 1 ); + + static_assert(!std::is_swappable_v&>); + static_assert(!std::is_swappable_v&>); + + return true; +} + +int +main() +{ + static_assert(test01()); + static_assert(test02()); + static_assert(test03()); + static_assert(test04()); + // FIXME: G++ doesn't support reading mutable members during constexpr (PR c++/92505). + test05(); + test06(); + test07(); + test08(); + test09(); +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/p2321.cc b/libstdc++-v3/testsuite/20_util/tuple/p2321.cc new file mode 100644 index 00000000000..80fc23cf9d4 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/p2321.cc @@ -0,0 +1,664 @@ +// Verify P2321R2 "zip" enhancements to std::tuple. +// { dg-options "-std=gnu++23" } +// { dg-do run { target c++23 } } + +#include +#include +#include + +using std::tuple; +using std::pair; +using std::allocator; +using std::allocator_arg_t; +using std::allocator_arg; + +namespace alloc { + struct B01; + struct B02; + struct B03; + struct B04; +} + +template<> struct std::uses_allocator> : std::true_type { }; +template<> struct std::uses_allocator> : std::true_type { }; +template<> struct std::uses_allocator> : std::true_type { }; +template<> struct std::uses_allocator> : std::true_type { }; + +struct A { }; + +constexpr bool +test01() +{ + struct B { bool v; constexpr B(A&) : v(true) { } }; + + // template + // constexpr explicit(false) tuple(tuple&); + + tuple t1a; + tuple t1b = t1a; + VERIFY( std::get<0>(t1b).v ); + + tuple t2a0; + tuple t2b0 = t2a0; + VERIFY( std::get<0>(t2b0).v ); + + tuple t2a1; + tuple t2b1 = t2a1; + VERIFY( std::get<1>(t2b1).v ); + + tuple t3a0; + tuple t3b0 = t3a0; + VERIFY( std::get<0>(t3b0).v ); + + tuple t3a1; + tuple t3b1 = t3a1; + VERIFY( std::get<1>(t3b1).v ); + + tuple t3a2; + tuple t3b2 = t3a2; + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(false) tuple(pair&); + + pair p2a0; + tuple p2b0 = p2a0; + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + tuple p2b1 = p2a1; + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +namespace alloc +{ + struct B01 + { + bool v; + B01(A&); + constexpr B01(allocator_arg_t, allocator, A&) : v(true) { } + }; + + constexpr bool + test01() + { + using B = B01; + + // template + // constexpr explicit(false) + // tuple(allocator_arg_t, const Alloc& a, tuple&); + + tuple t1a; + tuple t1b = {allocator_arg, allocator{}, t1a}; + VERIFY( std::get<0>(t1b).v ); + + tuple t2a0; + tuple t2b0 = {allocator_arg, allocator{}, t2a0}; + VERIFY( std::get<0>(t2b0).v ); + + tuple t2a1; + tuple t2b1 = {allocator_arg, allocator{}, t2a1}; + VERIFY( std::get<1>(t2b1).v ); + + tuple t3a0; + tuple t3b0 = {allocator_arg, allocator{}, t3a0}; + VERIFY( std::get<0>(t3b0).v ); + + tuple t3a1; + tuple t3b1 = {allocator_arg, allocator{}, t3a1}; + VERIFY( std::get<1>(t3b1).v ); + + tuple t3a2; + tuple t3b2 = {allocator_arg, allocator{}, t3a2}; + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(false) + // tuple(allocator_arg_t, const Alloc& a, pair&); + + pair p2a0; + tuple p2b0 = {allocator_arg, allocator{}, p2a0}; + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + tuple p2b1 = {allocator_arg, allocator{}, p2a1}; + VERIFY( std::get<1>(p2b1).v ); + + return true; + } +} + +constexpr bool +test02() +{ + struct B { bool v; explicit constexpr B(A&) : v(true) { } }; + + // template + // constexpr explicit(true) tuple(tuple&); + + static_assert(!std::is_convertible_v&, tuple>); + + tuple t1a; + tuple t1b(t1a); + VERIFY( std::get<0>(t1b).v ); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + tuple t2a0; + tuple t2b0(t2a0); + VERIFY( std::get<0>(t2b0).v ); + + tuple t2a1; + tuple t2b1(t2a1); + VERIFY( std::get<1>(t2b1).v ); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + tuple t3a0; + tuple t3b0(t3a0); + VERIFY( std::get<0>(t3b0).v ); + + tuple t3a1; + tuple t3b1(t3a1); + VERIFY( std::get<1>(t3b1).v ); + + tuple t3a2; + tuple t3b2(t3a2); + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(true) tuple(pair&); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + pair p2a0; + tuple p2b0(p2a0); + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + tuple p2b1(p2a1); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +namespace alloc +{ + struct B02 + { + bool v; + explicit B02(A&); + explicit constexpr B02(allocator_arg_t, allocator, A&) : v(true) { } + }; + + constexpr bool + test02() + { + using B = B02; + + // template + // constexpr explicit(true) + // tuple(allocator_arg_t, const Alloc& a, tuple&); + + tuple t1a; + tuple t1b(allocator_arg, allocator{}, t1a); + VERIFY( std::get<0>(t1b).v ); + + tuple t2a0; + tuple t2b0(allocator_arg, allocator{}, t2a0); + VERIFY( std::get<0>(t2b0).v ); + + tuple t2a1; + tuple t2b1(allocator_arg, allocator{}, t2a1); + VERIFY( std::get<1>(t2b1).v ); + + tuple t3a0; + tuple t3b0(allocator_arg, allocator{}, t3a0); + VERIFY( std::get<0>(t3b0).v ); + + tuple t3a1; + tuple t3b1(allocator_arg, allocator{}, t3a1); + VERIFY( std::get<1>(t3b1).v ); + + tuple t3a2; + tuple t3b2(allocator_arg, allocator{}, t3a2); + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(true) + // tuple(allocator_arg_t, const Alloc& a, pair&); + + pair p2a0; + tuple p2b0(allocator_arg, allocator{}, p2a0); + VERIFY( std::get<0>(p2b0).v ); + + pair p2a1; + tuple p2b1(allocator_arg, allocator{}, p2a1); + VERIFY( std::get<1>(p2b1).v ); + + return true; + } +} // namespace alloc + +constexpr bool +test03() +{ + struct B { bool v; constexpr B(const A&&) : v(true) { } }; + + // template + // constexpr explicit(false) tuple(const tuple&&); + + const tuple t1a; + tuple t1b = std::move(t1a); + VERIFY( std::get<0>(t1b).v ); + + const tuple t2a0; + tuple t2b0 = std::move(t2a0); + VERIFY( std::get<0>(t2b0).v ); + + const tuple t2a1; + tuple t2b1 = std::move(t2a1); + VERIFY( std::get<1>(t2b1).v ); + + const tuple t3a0; + tuple t3b0 = std::move(t3a0); + VERIFY( std::get<0>(t3b0).v ); + + const tuple t3a1; + tuple t3b1 = std::move(t3a1); + VERIFY( std::get<1>(t3b1).v ); + + const tuple t3a2; + tuple t3b2 = std::move(t3a2); + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(false) tuple(const pair&&); + + const pair p2a0; + tuple p2b0 = std::move(p2a0); + VERIFY( std::get<0>(p2b0).v ); + + const pair p2a1; + tuple p2b1 = std::move(p2a1); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +namespace alloc +{ + struct B03 + { + bool v; + B03(const A&&); + constexpr B03(allocator_arg_t, allocator, const A&&) : v(true) { } + }; + + constexpr bool + test03() + { + using B = B03; + + // template + // constexpr explicit(false) + // tuple(allocator_arg_t, const Alloc& a, const tuple&&); + + const tuple t1a; + tuple t1b = {allocator_arg, allocator{}, std::move(t1a)}; + VERIFY( std::get<0>(t1b).v ); + + const tuple t2a0; + tuple t2b0 = {allocator_arg, allocator{}, std::move(t2a0)}; + VERIFY( std::get<0>(t2b0).v ); + + const tuple t2a1; + tuple t2b1 = {allocator_arg, allocator{}, std::move(t2a1)}; + VERIFY( std::get<1>(t2b1).v ); + + const tuple t3a0; + tuple t3b0 = {allocator_arg, allocator{}, std::move(t3a0)}; + VERIFY( std::get<0>(t3b0).v ); + + const tuple t3a1; + tuple t3b1 = {allocator_arg, allocator{}, std::move(t3a1)}; + VERIFY( std::get<1>(t3b1).v ); + + const tuple t3a2; + tuple t3b2 = {allocator_arg, allocator{}, std::move(t3a2)}; + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(false) + // tuple(allocator_arg_t, const Alloc& a, const pair&&); + + const pair p2a0; + tuple p2b0 = {allocator_arg, allocator{}, std::move(p2a0)}; + VERIFY( std::get<0>(p2b0).v ); + + const pair p2a1; + tuple p2b1 = {allocator_arg, allocator{}, std::move(p2a1)}; + VERIFY( std::get<1>(p2b1).v ); + + return true; + } +}; + +constexpr bool +test04() +{ + struct B { bool v; explicit constexpr B(const A&&) : v(true) { } }; + + // template + // constexpr explicit(true) tuple(const tuple&&); + + static_assert(!std::is_convertible_v&, tuple>); + + const tuple t1a; + tuple t1b(std::move(t1a)); + VERIFY( std::get<0>(t1b).v ); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + const tuple t2a0; + tuple t2b0(std::move(t2a0)); + VERIFY( std::get<0>(t2b0).v ); + + const tuple t2a1; + tuple t2b1(std::move(t2a1)); + VERIFY( std::get<1>(t2b1).v ); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + const tuple t3a0; + tuple t3b0(std::move(t3a0)); + VERIFY( std::get<0>(t3b0).v ); + + const tuple t3a1; + tuple t3b1(std::move(t3a1)); + VERIFY( std::get<1>(t3b1).v ); + + const tuple t3a2; + tuple t3b2(std::move(t3a2)); + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(true) tuple(const pair&&); + + static_assert(!std::is_convertible_v&, tuple>); + static_assert(!std::is_convertible_v&, tuple>); + + const pair p2a0; + tuple p2b0(std::move(p2a0)); + VERIFY( std::get<0>(p2b0).v ); + + const pair p2a1; + tuple p2b1(std::move(p2a1)); + VERIFY( std::get<1>(p2b1).v ); + + return true; +} + +namespace alloc +{ + struct B04 + { + bool v; + explicit B04(const A&&); + explicit constexpr B04(allocator_arg_t, allocator, const A&&) : v(true) { } + }; + + constexpr bool + test04() + { + using B = B04; + + // template + // constexpr explicit(true) + // tuple(allocator_arg_t, const Alloc& a, const tuple&&); + + const tuple t1a; + tuple t1b(allocator_arg, allocator{}, std::move(t1a)); + VERIFY( std::get<0>(t1b).v ); + + const tuple t2a0; + tuple t2b0(allocator_arg, allocator{}, std::move(t2a0)); + VERIFY( std::get<0>(t2b0).v ); + + const tuple t2a1; + tuple t2b1(allocator_arg, allocator{}, std::move(t2a1)); + VERIFY( std::get<1>(t2b1).v ); + + const tuple t3a0; + tuple t3b0(allocator_arg, allocator{}, std::move(t3a0)); + VERIFY( std::get<0>(t3b0).v ); + + const tuple t3a1; + tuple t3b1(allocator_arg, allocator{}, std::move(t3a1)); + VERIFY( std::get<1>(t3b1).v ); + + const tuple t3a2; + tuple t3b2(allocator_arg, allocator{}, std::move(t3a2)); + VERIFY( std::get<2>(t3b2).v ); + + // template + // constexpr explicit(true) + // tuple(allocator_arg_t, const Alloc& a, const pair&&); + + tuple p2b0(allocator_arg, allocator{}, std::move(t2a0)); + VERIFY( std::get<0>(p2b0).v ); + + tuple p2b1(allocator_arg, allocator{}, std::move(t2a1)); + VERIFY( std::get<1>(p2b1).v ); + + return true; + } +}; + +constexpr bool +test05() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(const A&) const { v = true; return *this; } + }; + + // template + // constexpr const tuple& operator=(const tuple&) const; + + const tuple t1a; + const tuple t1b; + t1b = t1a; + VERIFY( std::get<0>(t1b).v ); + + const tuple t2a; + const tuple t2b; + t2b = t2a; + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + const tuple t3a; + const tuple t3b; + t3b = t3a; + VERIFY( std::get<0>(t3b).v ); + VERIFY( std::get<1>(t3b).v ); + VERIFY( std::get<2>(t3b).v ); + + // template + // constexpr const tuple& operator=(const pair&) const; + + const pair p2a; + const tuple p2b; + p2b = p2a; + + return true; +} + +constexpr bool +test06() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(A&&) const { v = true; return *this; } + }; + + // template + // constexpr const tuple& operator=(tuple&&) const; + + tuple t1a; + const tuple t1b; + t1b = std::move(t1a); + VERIFY( std::get<0>(t1b).v ); + + tuple t2a; + const tuple t2b; + t2b = std::move(t2a); + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + tuple t3a; + const tuple t3b; + t3b = std::move(t3a); + VERIFY( std::get<0>(t3b).v ); + VERIFY( std::get<1>(t3b).v ); + VERIFY( std::get<2>(t3b).v ); + + // template + // constexpr const tuple& operator=(pair&&) const; + + pair p2a; + const tuple p2b; + p2b = std::move(p2a); + + return true; +} + +constexpr bool +test07() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(const B&) const { v = true; return *this; } + }; + + // constexpr const tuple& operator=(const tuple&) const; + + const tuple t1a; + const tuple t1b; + t1b = t1a; + VERIFY( std::get<0>(t1b).v ); + + const tuple t2a; + const tuple t2b; + t2b = t2a; + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + const tuple t3a; + const tuple t3b; + t3b = t3a; + VERIFY( std::get<0>(t3b).v ); + VERIFY( std::get<1>(t3b).v ); + VERIFY( std::get<2>(t3b).v ); + + return true; +} + +constexpr bool +test08() +{ + struct B + { + mutable bool v; + constexpr const B& operator=(B&&) const { v = true; return *this; } + }; + + // constexpr const tuple& operator=(tuple&&) const; + + tuple t1a; + const tuple t1b; + t1b = std::move(t1a); + VERIFY( std::get<0>(t1b).v ); + + tuple t2a; + const tuple t2b; + t2b = std::move(t2a); + VERIFY( std::get<0>(t2b).v ); + VERIFY( std::get<1>(t2b).v ); + + tuple t3a; + const tuple t3b; + t3b = std::move(t3a); + VERIFY( std::get<0>(t3b).v ); + VERIFY( std::get<1>(t3b).v ); + VERIFY( std::get<2>(t3b).v ); + + return true; +} + +struct S +{ + mutable int v = 0; + friend constexpr void swap(S&& x, S&& y) = delete; + friend constexpr void swap(const S& x, const S& y) { ++x.v; ++y.v; } +}; + +constexpr bool +test09() +{ + const tuple t1, u1; + std::swap(t1, u1); + VERIFY( std::get<0>(t1).v == 1 ); + VERIFY( std::get<0>(u1).v == 1 ); + + const tuple t2, u2; + std::swap(t2, u2); + VERIFY( std::get<0>(t2).v == 1 ); + VERIFY( std::get<0>(u2).v == 1 ); + VERIFY( std::get<1>(t2).v == 1 ); + VERIFY( std::get<1>(u2).v == 1 ); + + const tuple t3, u3; + std::swap(t3, u3); + VERIFY( std::get<0>(t3).v == 1 ); + VERIFY( std::get<0>(u3).v == 1 ); + VERIFY( std::get<1>(t3).v == 1 ); + VERIFY( std::get<1>(u3).v == 1 ); + VERIFY( std::get<2>(t3).v == 1 ); + VERIFY( std::get<2>(u3).v == 1 ); + + static_assert(!std::is_swappable_v&>); + + return true; +} + +int +main() +{ + static_assert(test01()); + static_assert(alloc::test01()); + static_assert(test02()); + static_assert(alloc::test02()); + static_assert(test03()); + static_assert(alloc::test03()); + static_assert(test04()); + static_assert(alloc::test04()); + // FIXME: G++ doesn't support reading mutable members during constexpr (PR c++/92505). + test05(); + test06(); + test07(); + test08(); + test09(); +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc new file mode 100644 index 00000000000..9016c026b33 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc @@ -0,0 +1,26 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } +// { dg-xfail-if "not supported" { debug_mode } } + +#include +#include + +constexpr bool +test01() +{ + // P2321R2 + // constexpr const reference& vector::operator=(bool x) const noexcept; + + std::vector v(1); + const auto e = v[0]; + e = true; + VERIFY( v[0] ); + + return true; +} + +int +main() +{ + static_assert(test01()); +}