Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_streamiter.h
Go to the documentation of this file.
1
32#ifndef _RWSTD_RW_STREAMITER_H_INCLUDED
33#define _RWSTD_RW_STREAMITER_H_INCLUDED
34
35#ifndef _RWSTD_RW_ITERBASE_H_INCLUDED
36# include <rw/_iterbase.h>
37#endif // _RWSTD_RW_ITERBASE_H_INCLUDED
38
39#include <iosfwd>
40
41
43
44
45template <class _TypeT, class _CharT, class _Traits, class _Distance>
46class istream_iterator;
47
48template <class _TypeT, class _CharT, class _Traits, class _Distance>
49bool operator== (const istream_iterator<_TypeT, _CharT, _Traits, _Distance>&,
50 const istream_iterator<_TypeT, _CharT, _Traits, _Distance>&);
51
52// 24.5.1
53#if !defined (_MSC_VER) || _MSC_VER > 1300
54
55template <class _TypeT, class _CharT = char,
56 class _Traits = char_traits<_CharT>,
57 class _Distance = _RWSTD_PTRDIFF_T>
58#else
59
60// prevent MSVC 6.0 ICE
61template <class _TypeT, class _CharT, class _Traits, class _Distance>
62
63#endif
64
65class istream_iterator
66 : public iterator<input_iterator_tag, _TypeT, _Distance,
67 const _TypeT*, const _TypeT&>
68{
69 friend bool _RWSTD_SPECIALIZED_FRIEND (operator==)
70 (const istream_iterator&, const istream_iterator&);
71
72 typedef iterator<input_iterator_tag, _TypeT, _Distance,
73 const _TypeT*, const _TypeT&> _C_base;
74
75public:
76
77 typedef _CharT char_type;
78 typedef _Traits traits_type;
79 typedef basic_istream<char_type, traits_type> istream_type;
80
81 // for convenience
82 typedef typename _C_base::value_type value_type;
83
84 // 24.5.1.1, p1
85 istream_iterator (): _C_strm (0) { }
86
87 // 24.5.1.1, p2
88 istream_iterator (istream_type& __s)
89 : _C_strm (&__s) {
90 ++*this;
91 }
92
93 // 24.5.1.2, p1
94 const value_type& operator* () const {
95 return _C_val;
96 }
97
98 // 24.5.1.2, p2
99 _RWSTD_OPERATOR_ARROW (const value_type* operator->() const);
100
101 // 24.5.1.2, p3
102 istream_iterator& operator++ ();
103
104 // 24.5.1.2, p5
105 istream_iterator operator++ (int) {
106 istream_iterator __tmp = *this;
107 return ++*this, __tmp;
108 }
109
110protected:
111
112 istream_type *_C_strm; // associated stream
113 value_type _C_val; // last extracted value
114};
115
116
117template <class _TypeT, class _CharT, class _Traits, class _Distance>
118inline istream_iterator<_TypeT, _CharT, _Traits, _Distance>&
119istream_iterator<_TypeT, _CharT, _Traits, _Distance>::
120operator++ ()
121{
122 // incrementing an end-of-stream iterator has undefined behavior
123
124 // see also LWG issue 788
125 if (_C_strm && (*_C_strm >> _C_val).fail ())
126 _C_strm = 0;
127
128 return *this;
129}
130
131
132// 24.5.1.2, p6
133template <class _TypeT, class _CharT, class _Traits, class _Distance>
134inline bool
135operator== (const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __x,
136 const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __y)
137{
138 return __x._C_strm == __y._C_strm;
139}
140
141
142template <class _TypeT, class _CharT, class _Traits, class _Distance>
143inline bool
144operator!= (const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __x,
145 const istream_iterator<_TypeT, _CharT, _Traits, _Distance>& __y)
146{
147 return !(__x == __y);
148}
149
150
151// 24.5.2
152template <class _TypeT, class _CharT = char,
153 class _Traits = char_traits<_CharT> >
154struct ostream_iterator: iterator<output_iterator_tag, void, void, void, void>
155{
156 typedef _CharT char_type;
157 typedef _Traits traits_type;
158 typedef basic_ostream<char_type, traits_type> ostream_type;
159
160 // 24.5.2.1, p1, p2
161 ostream_iterator (ostream_type& __strm, const char_type* __s = 0)
162 : _C_strm (&__strm), _C_str (__s) { }
163
164 // 24.5.2.2, p1
165 ostream_iterator& operator= (const _TypeT &__val) {
166 *_C_strm << __val;
167 if (_C_str)
168 *_C_strm << _C_str;
169 return *this;
170 }
171
172 // 24.5.2.2, p2
173 ostream_iterator& operator* () {
174 return *this;
175 }
176
177 // 24.5.2.2, p3
178 ostream_iterator& operator++ () {
179 return *this;
180 }
181
182 ostream_iterator& operator++ (int) {
183 return *this;
184 }
185
186private:
187
188 ostream_type *_C_strm; // associated stream
189 const char_type *_C_str; // string to separate values with
190};
191
192
193} // namespace std
194
195
196#endif // _RWSTD_RW_STREAMITER_H_INCLUDED
int fail
const plus_asgn< T > & operator*(const plus_asgn< T > &lhs, const plus_asgn< T > &rhs)
#define _RWSTD_SPECIALIZED_FRIEND(name)
Definition _defs.h:600
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_OPERATOR_ARROW(signature)
Definition _defs.h:965
bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14737
bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
Definition json.h:14762
Definition json.h:5363