File indexing completed on 2026-05-03 08:13:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
0011 #define _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H
0012
0013 #include <__config>
0014 #include <__cstddef/ptrdiff_t.h>
0015 #include <__fwd/istream.h>
0016 #include <__fwd/string.h>
0017 #include <__iterator/default_sentinel.h>
0018 #include <__iterator/iterator.h>
0019 #include <__iterator/iterator_traits.h>
0020 #include <__memory/addressof.h>
0021
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 # pragma GCC system_header
0024 #endif
0025
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027
0028 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
0029 template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
0030 class _LIBCPP_TEMPLATE_VIS istream_iterator
0031 #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
0032 : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
0033 #endif
0034 {
0035 _LIBCPP_SUPPRESS_DEPRECATED_POP
0036
0037 public:
0038 typedef input_iterator_tag iterator_category;
0039 typedef _Tp value_type;
0040 typedef _Distance difference_type;
0041 typedef const _Tp* pointer;
0042 typedef const _Tp& reference;
0043 typedef _CharT char_type;
0044 typedef _Traits traits_type;
0045 typedef basic_istream<_CharT, _Traits> istream_type;
0046
0047 private:
0048 istream_type* __in_stream_;
0049 _Tp __value_;
0050
0051 public:
0052 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
0053 #if _LIBCPP_STD_VER >= 20
0054 _LIBCPP_HIDE_FROM_ABI constexpr istream_iterator(default_sentinel_t) : istream_iterator() {}
0055 #endif
0056 _LIBCPP_HIDE_FROM_ABI istream_iterator(istream_type& __s) : __in_stream_(std::addressof(__s)) {
0057 if (!(*__in_stream_ >> __value_))
0058 __in_stream_ = nullptr;
0059 }
0060
0061 _LIBCPP_HIDE_FROM_ABI const _Tp& operator*() const { return __value_; }
0062 _LIBCPP_HIDE_FROM_ABI const _Tp* operator->() const { return std::addressof((operator*())); }
0063 _LIBCPP_HIDE_FROM_ABI istream_iterator& operator++() {
0064 if (!(*__in_stream_ >> __value_))
0065 __in_stream_ = nullptr;
0066 return *this;
0067 }
0068 _LIBCPP_HIDE_FROM_ABI istream_iterator operator++(int) {
0069 istream_iterator __t(*this);
0070 ++(*this);
0071 return __t;
0072 }
0073
0074 template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
0075 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
0076 const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
0077
0078 #if _LIBCPP_STD_VER >= 20
0079 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator& __i, default_sentinel_t) {
0080 return __i.__in_stream_ == nullptr;
0081 }
0082 #endif
0083 };
0084
0085 template <class _Tp, class _CharT, class _Traits, class _Distance>
0086 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
0087 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) {
0088 return __x.__in_stream_ == __y.__in_stream_;
0089 }
0090
0091 #if _LIBCPP_STD_VER <= 17
0092 template <class _Tp, class _CharT, class _Traits, class _Distance>
0093 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
0094 const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) {
0095 return !(__x == __y);
0096 }
0097 #endif
0098
0099 _LIBCPP_END_NAMESPACE_STD
0100
0101 #endif