public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-6668] libstdc++: Make ranges::to closure objects SFINAE-friendly [PR112802] Date: Mon, 18 Dec 2023 23:06:23 +0000 (GMT) [thread overview] Message-ID: <20231218230623.74DA73858417@sourceware.org> (raw) https://gcc.gnu.org/g:4f54e656788be3268dd45eb036447464a937fae9 commit r14-6668-g4f54e656788be3268dd45eb036447464a937fae9 Author: Patrick Palka <ppalka@redhat.com> Date: Mon Dec 18 18:05:36 2023 -0500 libstdc++: Make ranges::to closure objects SFINAE-friendly [PR112802] This also happens to fix composition of these closure objects. PR libstdc++/112802 PR libstdc++/113068 libstdc++-v3/ChangeLog: * include/std/ranges (__detail::_To::operator()): Add constraints. (__detail::_To2::operator()): Likewise. * testsuite/std/ranges/conv/1.cc (test_sfinae): New test. (test_composition): New test. Diff: --- libstdc++-v3/include/std/ranges | 4 ++++ libstdc++-v3/testsuite/std/ranges/conv/1.cc | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index be8475c0cb1..752a04e01bd 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -9389,6 +9389,8 @@ namespace __detail struct _To { template<typename _Range, typename... _Args> + requires requires { ranges::to<_Cont>(std::declval<_Range>(), + std::declval<_Args>()...); } constexpr auto operator()(_Range&& __r, _Args&&... __args) const { @@ -9431,6 +9433,8 @@ namespace __detail struct _To2 { template<typename _Range, typename... _Args> + requires requires { ranges::to<_Cont>(std::declval<_Range>(), + std::declval<_Args>()...); } constexpr auto operator()(_Range&& __r, _Args&&... __args) const { diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc b/libstdc++-v3/testsuite/std/ranges/conv/1.cc index 6d6a708ab64..09fd515edf1 100644 --- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc +++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc @@ -448,6 +448,24 @@ test_constexpr() static_assert(x == 6); } +void +test_sfinae() +{ + // PR libstdc++/112802 + [](auto x) { + static_assert(!requires { std::ranges::to<std::vector<int>>()(x); }); + static_assert(!requires { std::ranges::to<std::vector>()(x); }); + }(0); +} + +void +test_composition() +{ + // PR libstdc++/113068 + auto adaptor = std::ranges::to<std::string>() | std::ranges::to<std::string>(); + auto str = adaptor(" "); +} + int main() { test_p1206r7_examples(); @@ -460,4 +478,6 @@ int main() test_lwg3984(); test_nodiscard(); test_constexpr(); + test_sfinae(); + test_composition(); }
reply other threads:[~2023-12-18 23:06 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231218230623.74DA73858417@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@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).