aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-02-24 13:11:31 +0000
committerJonathan Wakely <jwakely@redhat.com>2020-02-24 13:39:18 +0000
commit120e873484f20d9a0b8400e2e464ac5b2088a747 (patch)
treeff85bf825e28dc76d68a89a0b614502e79d097da /libstdc++-v3/include
parente03069be127cbc9d134d3f6b3c41461fed630444 (diff)
downloadgcc-120e873484f20d9a0b8400e2e464ac5b2088a747.zip
gcc-120e873484f20d9a0b8400e2e464ac5b2088a747.tar.gz
gcc-120e873484f20d9a0b8400e2e464ac5b2088a747.tar.bz2
libstdc++: Add default_sentinel support to stream iterators
Missing pieces of P0896R4 "The One Ranges Proposal" for C++20. * include/bits/stream_iterator.h (istream_iterator(default_sentinel_t)): Add constructor. (operator==(istream_iterator, default_sentinel_t)): Add operator. (ostream_iterator::difference_type): Define to ptrdiff_t for C++20. * include/bits/streambuf_iterator.h (istreambuf_iterator(default_sentinel_t)): Add constructor. (operator==(istreambuf_iterator, default_sentinel_t)): Add operator. * testsuite/24_iterators/istream_iterator/cons/sentinel.cc: New test. * testsuite/24_iterators/istream_iterator/sentinel.cc: New test. * testsuite/24_iterators/istreambuf_iterator/cons/sentinel.cc: New test. * testsuite/24_iterators/istreambuf_iterator/sentinel.cc: New test.
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/stream_iterator.h15
-rw-r--r--libstdc++-v3/include/bits/streambuf_iterator.h11
2 files changed, 26 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h
index 345a4d8..1ddf647 100644
--- a/libstdc++-v3/include/bits/stream_iterator.h
+++ b/libstdc++-v3/include/bits/stream_iterator.h
@@ -77,6 +77,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_ok(__obj._M_ok)
{ }
+#if __cplusplus > 201703L
+ constexpr
+ istream_iterator(default_sentinel_t) noexcept
+ : istream_iterator() { }
+#endif
+
#if __cplusplus >= 201103L
istream_iterator& operator=(const istream_iterator&) = default;
~istream_iterator() = default;
@@ -145,6 +151,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend bool
operator!=(const istream_iterator& __x, const istream_iterator& __y)
{ return !__x._M_equal(__y); }
+
+#if __cplusplus > 201703L
+ friend bool
+ operator==(const istream_iterator& __i, default_sentinel_t)
+ { return !__i._M_stream; }
+#endif
};
/**
@@ -166,6 +178,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public:
//@{
/// Public typedef
+#if __cplusplus > 201703L
+ using difference_type = ptrdiff_t;
+#endif
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index fe612f3..fc06c50 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -115,6 +115,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_CONSTEXPR istreambuf_iterator() _GLIBCXX_USE_NOEXCEPT
: _M_sbuf(0), _M_c(traits_type::eof()) { }
+#if __cplusplus > 201703L
+ constexpr istreambuf_iterator(default_sentinel_t) noexcept
+ : istreambuf_iterator() { }
+#endif
+
#if __cplusplus >= 201103L
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
@@ -209,6 +214,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
const int_type __eof = traits_type::eof();
return traits_type::eq_int_type(__c, __eof);
}
+
+#if __cplusplus > 201703L
+ friend bool
+ operator==(const istreambuf_iterator& __i, default_sentinel_t __s)
+ { return __i._M_at_eof(); }
+#endif
};
template<typename _CharT, typename _Traits>