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.133.124]) by sourceware.org (Postfix) with ESMTPS id 25C1F3858D20 for ; Thu, 9 Mar 2023 17:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25C1F3858D20 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=1678384354; 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: in-reply-to:in-reply-to:references:references; bh=pAYlZmZr4trNNq5MfD2UgJWYuPMuJVaa5Dn4sy0ICA8=; b=OiRZp0/MUuKzFa360j2x5Wsm0fm1gAMF4PBrn1WzQ/mSw382mfsrnfEykMGCflIQv1dMZ6 ApXESwSfj5KvoyF5snq/zyQKeq6rjBCw+couF3y4ZNWWWJ2smC+61nlKAZg1ojqOejSxFM 43c8rLVi0tBWz4WPs3REDFij0LBL83M= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-J1q_RB2wOlGEF4DtjjLblQ-1; Thu, 09 Mar 2023 12:52:33 -0500 X-MC-Unique: J1q_RB2wOlGEF4DtjjLblQ-1 Received: by mail-lf1-f72.google.com with SMTP id k7-20020ac257c7000000b004db20d1cf7fso843146lfo.18 for ; Thu, 09 Mar 2023 09:52:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678384352; h=cc: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=pAYlZmZr4trNNq5MfD2UgJWYuPMuJVaa5Dn4sy0ICA8=; b=YcxGpQ++uBS5AjE/ZChBpGhNv06SjSv37qOZK+fKD+CUFaTRw3+9KEaSSP6NPuPXL9 WA423RwiHUBXKJ0Usol19S6cn3mTXesdGhnGs0059rXDn0Ab+/lq0jOiMagpmOCToP52 3hHvy5h3FU5Dgkdi1HGnUG8Yc0821Yj0AHL3abtpSI2yp6qNAoTntqaJ2O8OZ5OP82Y6 3v0ZrXFg/DAP5JWr+sJpW1xu/DPkSP9F8HComy3NsT9KRFuhVZFnnWBbcZrniUKc3zn5 jvJGJ7vmJdDJA3P3pqI1C6vuJ4jmGRFMPLbHKewzjY4OEasOEumKBjetkJP/R6V97Ueq vELg== X-Gm-Message-State: AO0yUKWa//pOom9IK9LlCY3CkVZWN3RPM0JLpks6fuf7rdBrgCp8dhmD 2jGrVPt45CFY0KZAUSr5kPaqUZaLmIPgt9HPCOd4x+n4zXPTUniquToWOAOnQ3t/nJWu/nJWpiJ ORL/D9yMNP15mE2kae6L0nRwZA0zO7l8= X-Received: by 2002:a05:6512:68:b0:4d8:5f47:e4d3 with SMTP id i8-20020a056512006800b004d85f47e4d3mr6874908lfo.8.1678384352171; Thu, 09 Mar 2023 09:52:32 -0800 (PST) X-Google-Smtp-Source: AK7set+TSVBeJGJRuFH2uM5xjf6QFfyUU0++QNvEIMKvVyA40LDyKrUWpMaqJonri+YjHXI0sqlK28/4sojjUIGrSfE= X-Received: by 2002:a05:6512:68:b0:4d8:5f47:e4d3 with SMTP id i8-20020a056512006800b004d85f47e4d3mr6874905lfo.8.1678384351857; Thu, 09 Mar 2023 09:52:31 -0800 (PST) MIME-Version: 1.0 References: <20230308143527.113337-1-ppalka@redhat.com> In-Reply-To: <20230308143527.113337-1-ppalka@redhat.com> From: Jonathan Wakely Date: Thu, 9 Mar 2023 17:52:20 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Make views::single/iota/istream SFINAE-friendly [PR108362] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@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=-12.1 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: On Wed, 8 Mar 2023 at 14:36, Patrick Palka via Libstdc++ wrote: > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 12? Yes, OK for trunk and 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 >