aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-09-30 14:39:36 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-10-01 15:04:02 +0100
commit901fa4cc27ce693b361220818732556bfa586eea (patch)
treeb2404f52d6a59f7457dd466b0514b1c2f998d68d
parentc67339d12653c33f85f8141789d7a7cf38831cbd (diff)
downloadgcc-901fa4cc27ce693b361220818732556bfa586eea.zip
gcc-901fa4cc27ce693b361220818732556bfa586eea.tar.gz
gcc-901fa4cc27ce693b361220818732556bfa586eea.tar.bz2
libstdc++: Add noexcept to istream_iterator and ostream_iterator
libstdc++-v3/ChangeLog: * include/bits/stream_iterator.h (istream_iterator): Add noexcept to constructors and non-throwing member functions and friend functions. (ostream_iterator): Likewise.
-rw-r--r--libstdc++-v3/include/bits/stream_iterator.h25
1 files changed, 15 insertions, 10 deletions
diff --git a/libstdc++-v3/include/bits/stream_iterator.h b/libstdc++-v3/include/bits/stream_iterator.h
index d74c158..5a13231 100644
--- a/libstdc++-v3/include/bits/stream_iterator.h
+++ b/libstdc++-v3/include/bits/stream_iterator.h
@@ -65,6 +65,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public:
/// Construct end of input stream iterator.
_GLIBCXX_CONSTEXPR istream_iterator()
+ _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Tp>::value)
: _M_stream(0), _M_value(), _M_ok(false) {}
/// Construct start of input stream iterator.
@@ -73,6 +74,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ _M_read(); }
istream_iterator(const istream_iterator& __obj)
+ _GLIBCXX_NOEXCEPT_IF(is_nothrow_copy_constructible<_Tp>::value)
: _M_stream(__obj._M_stream), _M_value(__obj._M_value),
_M_ok(__obj._M_ok)
{ }
@@ -91,7 +93,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NODISCARD
const _Tp&
- operator*() const
+ operator*() const _GLIBCXX_NOEXCEPT
{
__glibcxx_requires_cond(_M_ok,
_M_message(__gnu_debug::__msg_deref_istream)
@@ -101,7 +103,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NODISCARD
const _Tp*
- operator->() const { return std::__addressof((operator*())); }
+ operator->() const _GLIBCXX_NOEXCEPT
+ { return std::__addressof((operator*())); }
istream_iterator&
operator++()
@@ -126,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private:
bool
- _M_equal(const istream_iterator& __x) const
+ _M_equal(const istream_iterator& __x) const _GLIBCXX_NOEXCEPT
{
// Ideally this would just return _M_stream == __x._M_stream,
// but code compiled with old versions never sets _M_stream to null.
@@ -148,6 +151,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NODISCARD
friend bool
operator==(const istream_iterator& __x, const istream_iterator& __y)
+ _GLIBCXX_NOEXCEPT
{ return __x._M_equal(__y); }
#if __cpp_impl_three_way_comparison < 201907L
@@ -156,13 +160,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NODISCARD
friend bool
operator!=(const istream_iterator& __x, const istream_iterator& __y)
+ _GLIBCXX_NOEXCEPT
{ return !__x._M_equal(__y); }
#endif
#if __cplusplus > 201703L && __cpp_lib_concepts
[[nodiscard]]
friend bool
- operator==(const istream_iterator& __i, default_sentinel_t)
+ operator==(const istream_iterator& __i, default_sentinel_t) noexcept
{ return !__i._M_stream; }
#endif
};
@@ -200,7 +205,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
public:
/// Construct from an ostream.
- ostream_iterator(ostream_type& __s)
+ ostream_iterator(ostream_type& __s) _GLIBCXX_NOEXCEPT
: _M_stream(std::__addressof(__s)), _M_string(0) {}
/**
@@ -213,11 +218,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __s Underlying ostream to write to.
* @param __c CharT delimiter string to insert.
*/
- ostream_iterator(ostream_type& __s, const _CharT* __c)
+ ostream_iterator(ostream_type& __s, const _CharT* __c) _GLIBCXX_NOEXCEPT
: _M_stream(std::__addressof(__s)), _M_string(__c) { }
/// Copy constructor.
- ostream_iterator(const ostream_iterator& __obj)
+ ostream_iterator(const ostream_iterator& __obj) _GLIBCXX_NOEXCEPT
: _M_stream(__obj._M_stream), _M_string(__obj._M_string) { }
#if __cplusplus >= 201103L
@@ -240,15 +245,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_NODISCARD
ostream_iterator&
- operator*()
+ operator*() _GLIBCXX_NOEXCEPT
{ return *this; }
ostream_iterator&
- operator++()
+ operator++() _GLIBCXX_NOEXCEPT
{ return *this; }
ostream_iterator&
- operator++(int)
+ operator++(int) _GLIBCXX_NOEXCEPT
{ return *this; }
};