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 r12-4615] libstdc++: Implement P2432R1 changes for views::istream Date: Thu, 21 Oct 2021 15:57:57 +0000 (GMT) [thread overview] Message-ID: <20211021155757.3F90B385780B@sourceware.org> (raw) https://gcc.gnu.org/g:48154969d4b2e530af68ae9cd4277facf9d3f1a2 commit r12-4615-g48154969d4b2e530af68ae9cd4277facf9d3f1a2 Author: Patrick Palka <ppalka@redhat.com> Date: Thu Oct 21 11:55:19 2021 -0400 libstdc++: Implement P2432R1 changes for views::istream libstdc++-v3/ChangeLog: * include/std/ranges (istream_view): Replace this function template with an alias template as per P2432R1. (wistream_view): Define as per P2432R1. (views::_Istream, views::istream): Likewise. * testsuite/std/ranges/istream_view.cc (test07): New test. Diff: --- libstdc++-v3/include/std/ranges | 25 +++++++++++++++++++---- libstdc++-v3/testsuite/std/ranges/istream_view.cc | 13 ++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index d6bb78c09f9..7521cd675b3 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -782,10 +782,27 @@ namespace views friend _Iterator; }; - template<typename _Val, typename _CharT, typename _Traits> - basic_istream_view<_Val, _CharT, _Traits> - istream_view(basic_istream<_CharT, _Traits>& __s) - { return basic_istream_view<_Val, _CharT, _Traits>{__s}; } + template<typename _Val> + using istream_view = basic_istream_view<_Val, char>; + + template<typename _Val> + using wistream_view = basic_istream_view<_Val, wchar_t>; + +namespace views +{ + template<typename _Tp> + struct _Istream + { + template<typename _CharT, typename _Traits> + [[nodiscard]] + constexpr auto + operator()(basic_istream<_CharT, _Traits>& __e) const + { return basic_istream_view<_Tp, _CharT, _Traits>(__e); } + }; + + template<typename _Tp> + inline constexpr _Istream<_Tp> istream; +} // C++20 24.7 [range.adaptors] Range adaptors diff --git a/libstdc++-v3/testsuite/std/ranges/istream_view.cc b/libstdc++-v3/testsuite/std/ranges/istream_view.cc index f5c0c2a6bb0..ea7c5a35ef7 100644 --- a/libstdc++-v3/testsuite/std/ranges/istream_view.cc +++ b/libstdc++-v3/testsuite/std/ranges/istream_view.cc @@ -103,6 +103,18 @@ test06() static_assert( std::is_same_v<V, W> ); } +void +test07() +{ + // P2432R1, views::istream + auto nums = std::istringstream("0 1 2 3 4"); + ranges::istream_view<int> v(nums); + int sum = 0; + for (int val : views::istream<int>(nums)) + sum += val; + VERIFY( sum == 10 ); +} + int main() { @@ -112,4 +124,5 @@ main() test04(); test05(); test06(); + test07(); }
reply other threads:[~2021-10-21 15:57 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=20211021155757.3F90B385780B@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).