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 45BA33858289 for ; Wed, 8 Mar 2023 14:35:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 45BA33858289 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678286134; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=c5GhCg10ZSeJ4BhCwtf99Amj6Lzk5/2JnBOehEhJpsA=; b=PNlVHU1wZcVbXEH093/G9JJauciGZqQ0GEN5yg72oAiha4bHm3vpngrY32jR1eExdSRHGW nEPGCel3e46DMS8XmIlI8l7X+DSBc1VCAIBp0wsEWdF9OYdGqy9Dl/wmpj0aJH352PMMom 2j5loIIr1evZxt8LciYrLdYXQyxHROk= 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_256_GCM_SHA384) id us-mta-651-58ksmyBjNmmm1x9-CRwUlQ-1; Wed, 08 Mar 2023 09:35:33 -0500 X-MC-Unique: 58ksmyBjNmmm1x9-CRwUlQ-1 Received: by mail-qt1-f199.google.com with SMTP id i24-20020ac84f58000000b003bfe3358691so9132607qtw.21 for ; Wed, 08 Mar 2023 06:35:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678286133; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=c5GhCg10ZSeJ4BhCwtf99Amj6Lzk5/2JnBOehEhJpsA=; b=FTTlHOHupCPycQ4vas+HeyElPn/KR940piVIoiNle1P+y1+e6tgGRh8sxvAeeQ9B4W nAlRwLS1rrLxWzv0/uB+HNGPjfNYM7JREeONwzaWSl/gjADIdGbRWwdgPh4ZQhd+dzvU 9c4hAN3w7s5CPZfZ9BELD1UXNgQtkbYy3KTKVjekf/6gYjVcSrWas4FBpudyDctdsmdP EPoysyZ0eoEfxk87tRp5qweSudTWZ28iKPo0oym9GWNbuD5wlg9cg3ctMBg0vSvDdYqB JSk199qFpCrXfxhwd4AAjZ0BQZBLj6Arr5hdHD4CBm2ycUpB/U+MUnYvXV1eiv0fT0ts HMHQ== X-Gm-Message-State: AO0yUKXfGTaDkQ1Ql8PGiLWffvK7mInseWys1cqX888L/ajCBSxEJGec 4y0KBPz/jTsHe3hW2CktNlfEJIuvgJexwSLWNKkqlKnkkhXPePuNUJ7A0nt1xEXil8Li1/c36sK kVfFxW+LdLhNAhVA= X-Received: by 2002:a05:6214:b6e:b0:56e:a6c6:445a with SMTP id ey14-20020a0562140b6e00b0056ea6c6445amr33262839qvb.31.1678286133063; Wed, 08 Mar 2023 06:35:33 -0800 (PST) X-Google-Smtp-Source: AK7set96tBUyi4mH0kVtjl2I2mc1kx52UqSe578NCdcTKW5v70tnnI2ppSDaCjxyiOfY9TUl1QMJAQ== X-Received: by 2002:a05:6214:b6e:b0:56e:a6c6:445a with SMTP id ey14-20020a0562140b6e00b0056ea6c6445amr33262796qvb.31.1678286132716; Wed, 08 Mar 2023 06:35:32 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 6-20020a05620a040600b006f9ddaaf01esm11436322qkp.102.2023.03.08.06.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 06:35:32 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Make views::single/iota/istream SFINAE-friendly [PR108362] Date: Wed, 8 Mar 2023 09:35:27 -0500 Message-Id: <20230308143527.113337-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0.rc0.57.g454dfcbddf MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 12? PR libstdc++/108362 libstdc++-v3/ChangeLog: * include/std/ranges (__detail::__can_single_view): New concept. (_Single::operator()): Constrain it. Move [[nodiscard]] to the end of the function declarator. (__detail::__can_iota_view): New concept. (_Iota::operator()): Constrain it. Move [[nodiscard]] to the end of the function declarator. (__detail::__can_istream_view): New concept. (_Istream::operator()): Constrain it. Move [[nodiscard]] to the end of the function declarator. * testsuite/std/ranges/iota/iota_view.cc (test07): New test. * testsuite/std/ranges/istream_view.cc (test08): New test. * testsuite/std/ranges/single_view.cc (test07): New test. --- libstdc++-v3/include/std/ranges | 40 ++++++++++++++----- .../testsuite/std/ranges/iota/iota_view.cc | 10 +++++ .../testsuite/std/ranges/istream_view.cc | 12 ++++++ .../testsuite/std/ranges/single_view.cc | 13 ++++++ 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 0a65d74bb5b..67566c6ebcf 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -675,30 +675,41 @@ namespace views template inline constexpr empty_view<_Tp> empty{}; + namespace __detail + { + template + concept __can_single_view + = requires { single_view>(std::declval<_Tp>()); }; + } // namespace __detail + struct _Single { - template - [[nodiscard]] + template<__detail::__can_single_view _Tp> constexpr auto - operator()(_Tp&& __e) const + operator() [[nodiscard]] (_Tp&& __e) const noexcept(noexcept(single_view>(std::forward<_Tp>(__e)))) { return single_view>(std::forward<_Tp>(__e)); } }; inline constexpr _Single single{}; + namespace __detail + { + template + concept __can_iota_view = requires { iota_view(std::declval<_Args>()...); }; + } // namespace __detail + struct _Iota { - template - [[nodiscard]] + template<__detail::__can_iota_view _Tp> constexpr auto - operator()(_Tp&& __e) const + operator() [[nodiscard]] (_Tp&& __e) const { return iota_view(std::forward<_Tp>(__e)); } template - [[nodiscard]] + requires __detail::__can_iota_view<_Tp, _Up> constexpr auto - operator()(_Tp&& __e, _Up&& __f) const + operator() [[nodiscard]] (_Tp&& __e, _Up&& __f) const { return iota_view(std::forward<_Tp>(__e), std::forward<_Up>(__f)); } }; @@ -796,13 +807,22 @@ namespace views namespace views { + namespace __detail + { + template + concept __can_istream_view + = requires (_Up __e) { + basic_istream_view<_Tp, typename _Up::char_type, typename _Up::traits_type>(__e); + }; + }; + template struct _Istream { template - [[nodiscard]] constexpr auto - operator()(basic_istream<_CharT, _Traits>& __e) const + operator() [[nodiscard]] (basic_istream<_CharT, _Traits>& __e) const + requires __detail::__can_istream_view<_Tp, std::remove_reference_t> { return basic_istream_view<_Tp, _CharT, _Traits>(__e); } }; diff --git a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc index 2dd17113536..0d2eaf1d0c2 100644 --- a/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/iota/iota_view.cc @@ -110,6 +110,15 @@ test06() VERIFY( std::ranges::equal(v3, w3) ); } +template +void +test07() +{ + // Verify SFINAE behavior. + static_assert(!requires { iota(nullptr); }); + static_assert(!requires { iota(nullptr, nullptr); }); +} + int main() { @@ -119,4 +128,5 @@ main() test04(); test05(); test06(); + test07(); } diff --git a/libstdc++-v3/testsuite/std/ranges/istream_view.cc b/libstdc++-v3/testsuite/std/ranges/istream_view.cc index 26f109fdeaa..cc1c3e006b9 100644 --- a/libstdc++-v3/testsuite/std/ranges/istream_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/istream_view.cc @@ -115,6 +115,17 @@ test07() VERIFY( sum == 10 ); } +template +concept can_istream_view = requires (U u) { views::istream(u); }; + +void +test08() +{ + // Verify SFINAE behavior. + struct S { }; + static_assert(!can_istream_view); +} + int main() { @@ -125,4 +136,5 @@ main() test05(); test06(); test07(); + test08(); } diff --git a/libstdc++-v3/testsuite/std/ranges/single_view.cc b/libstdc++-v3/testsuite/std/ranges/single_view.cc index 063caeb8785..38a3946ca43 100644 --- a/libstdc++-v3/testsuite/std/ranges/single_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/single_view.cc @@ -111,6 +111,18 @@ test06() auto y = std::views::single(std::move(obj)); } +template +void +test07() +{ + // Verify SFINAE behavior. + struct uncopyable { + uncopyable(); + uncopyable(const uncopyable&) = delete; + }; + static_assert(!requires { single(uncopyable{}); }); +} + int main() { test01(); @@ -119,4 +131,5 @@ int main() test04(); test05(); test06(); + test07(); } -- 2.40.0.rc0.57.g454dfcbddf