public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH 4/3] Add [range.istream]
Date: Fri, 07 Feb 2020 12:14:00 -0000	[thread overview]
Message-ID: <20200207121443.GQ9441@redhat.com> (raw)
In-Reply-To: <20200207005252.1685890-1-ppalka@redhat.com>

On 06/02/20 19:52 -0500, Patrick Palka wrote:
>This patch adds ranges::basic_istream_view and ranges::istream_view.  This seems
>to be the last missing part of the ranges header.
>
>libstdc++-v3/ChangeLog:
>
>	* include/std/ranges (ranges::__detail::__stream_extractable,
>	ranges::basic_istream_view, ranges::istream_view): Define.
>	* testsuite/std/ranges/istream_view: New test.
>---
> libstdc++-v3/include/std/ranges               | 94 +++++++++++++++++++
> .../testsuite/std/ranges/istream_view.cc      | 76 +++++++++++++++
> 2 files changed, 170 insertions(+)
> create mode 100644 libstdc++-v3/testsuite/std/ranges/istream_view.cc
>
>diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
>index 8a8fefb6f19..88b98310ef9 100644
>--- a/libstdc++-v3/include/std/ranges
>+++ b/libstdc++-v3/include/std/ranges
>@@ -951,6 +951,100 @@ namespace views
>   inline constexpr _Iota iota{};
> } // namespace views
>
>+  namespace __detail
>+  {
>+    template<typename _Val, typename _CharT, typename _Traits>
>+      concept __stream_extractable
>+	= requires(basic_istream<_CharT, _Traits>& is, _Val& t) { is >> t; };

I was going to ask for "is" and "t" to use reserved names, but those
names are actually reserved. std::ctype::is is present since C++98 and
std::binomial_distribution::t() since C++11. So the names are OK.

>+  } // namespace __detail
>+
>+  template<movable _Val, typename _CharT, typename _Traits>
>+    requires default_initializable<_Val>
>+      && __detail::__stream_extractable<_Val, _CharT, _Traits>
>+    class basic_istream_view
>+    : public view_interface<basic_istream_view<_Val, _CharT, _Traits>>
>+    {
>+    public:
>+      basic_istream_view() = default;
>+
>+      constexpr explicit
>+      basic_istream_view(basic_istream<_CharT, _Traits>& __stream)
>+	: _M_stream(std::__addressof(__stream))
>+      { }
>+
>+      constexpr auto
>+      begin()
>+      {
>+	if (_M_stream != nullptr)
>+	  *_M_stream >> _M_object;
>+	return _Iterator{*this};
>+      }
>+
>+      constexpr default_sentinel_t
>+      end() const noexcept
>+      { return default_sentinel; }
>+
>+    private:
>+      basic_istream<_CharT, _Traits>* _M_stream = nullptr;
>+      _Val _M_object = _Val();
>+
>+      struct _Iterator
>+      {
>+      public:
>+	using iterator_category = input_iterator_tag;
>+	using difference_type = ptrdiff_t;
>+	using value_type = _Val;
>+
>+	_Iterator() = default;
>+
>+	constexpr explicit
>+	_Iterator(basic_istream_view& __parent) noexcept
>+	  : _M_parent(std::__addressof(__parent))
>+	{ }
>+
>+	_Iterator(const _Iterator&) = delete;
>+	_Iterator(_Iterator&&) = default;
>+	_Iterator& operator=(const _Iterator&) = delete;
>+	_Iterator& operator=(_Iterator&&) = default;
>+
>+	_Iterator&
>+	operator++()
>+	{
>+	  __glibcxx_assert(_M_parent->_M_stream != nullptr);
>+	  *_M_parent->_M_stream >> _M_parent->_M_object;
>+	}
>+
>+	void
>+	operator++(int)
>+	{ ++*this; }
>+
>+	_Val&
>+	operator*() const
>+	{
>+	  __glibcxx_assert(_M_parent->_M_stream != nullptr);
>+	  return _M_parent->_M_object;
>+	}
>+
>+	friend bool
>+	operator==(const _Iterator& __x, default_sentinel_t)
>+	{ return __x.__at_end(); }
>+
>+      private:
>+	basic_istream_view* _M_parent = nullptr;
>+
>+	bool
>+	__at_end() const

Please rename this to _M_at_end for consistency with the rest of the
library.

OK for master with that tweak, thanks.

  reply	other threads:[~2020-02-07 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-07  0:53 Patrick Palka
2020-02-07 12:14 ` Jonathan Wakely [this message]
2020-02-07 14:46   ` Patrick Palka
2020-02-07 16:18     ` Jonathan Wakely

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=20200207121443.GQ9441@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /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: link
Be 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).