📄 stl_iterator.h
字号:
void _M_postincr_aux(); void _M_nextc() { int_type __c = _M_buf->snextc(); _M_c = traits_type::to_char_type(__c); _M_eof = traits_type::eq_int_type(__c, traits_type::eof()); _M_is_initialized = true; } void _M_getc() const { int_type __c = _M_buf->sgetc(); _M_c = traits_type::to_char_type(__c); _M_eof = traits_type::eq_int_type(__c, traits_type::eof()); _M_is_initialized = true; }private: streambuf_type* _M_buf; mutable _CharT _M_c; mutable bool _M_eof : 1; mutable bool _M_is_initialized : 1;};template<class _CharT, class _Traits>_CharT istreambuf_iterator<_CharT, _Traits>::_M_dereference_aux() const{ this->_M_getc(); return _M_c;}template<class _CharT, class _Traits>bool istreambuf_iterator<_CharT, _Traits> ::_M_equal_aux(const istreambuf_iterator& __i) const{ if (!this->_M_is_initialized) this->_M_getc(); if (!__i._M_is_initialized) __i._M_getc(); return this->_M_eof == __i._M_eof;}template<class _CharT, class _Traits>void istreambuf_iterator<_CharT, _Traits>::_M_postincr_aux(){ this->_M_getc();}template<class _CharT, class _Traits>inline bool operator==(const istreambuf_iterator<_CharT, _Traits>& __x, const istreambuf_iterator<_CharT, _Traits>& __y) { return __x.equal(__y);}#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDERtemplate<class _CharT, class _Traits>inline bool operator!=(const istreambuf_iterator<_CharT, _Traits>& __x, const istreambuf_iterator<_CharT, _Traits>& __y) { return !__x.equal(__y);}#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */// The default template argument is declared in iosfwdtemplate<class _CharT, class _Traits>class ostreambuf_iterator{public: typedef _CharT char_type; typedef _Traits traits_type; typedef typename _Traits::int_type int_type; typedef basic_streambuf<_CharT, _Traits> streambuf_type; typedef basic_ostream<_CharT, _Traits> ostream_type; typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference;public: ostreambuf_iterator(streambuf_type* __buf) : _M_buf(__buf), _M_ok(__buf) {} ostreambuf_iterator(ostream_type& __o) : _M_buf(__o.rdbuf()), _M_ok(__o.rdbuf()) {} ostreambuf_iterator& operator=(char_type __c) { _M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c), traits_type::eof()); return *this; } ostreambuf_iterator& operator*() { return *this; } ostreambuf_iterator& operator++() { return *this; } ostreambuf_iterator& operator++(int) { return *this; } bool failed() const { return !_M_ok; }private: streambuf_type* _M_buf; bool _M_ok;};#else /* __STL_USE_NEW_IOSTREAMS */template <class _Tp, class _Dist = ptrdiff_t> class istream_iterator;template <class _Tp, class _Dist>inline bool operator==(const istream_iterator<_Tp, _Dist>&, const istream_iterator<_Tp, _Dist>&);template <class _Tp, class _Dist>class istream_iterator {#ifdef __STL_MEMBER_TEMPLATES template <class _T1, class _D1> friend bool operator==(const istream_iterator<_T1, _D1>&, const istream_iterator<_T1, _D1>&);#else /* __STL_MEMBER_TEMPLATES */ friend bool __STD_QUALIFIER operator== __STL_NULL_TMPL_ARGS (const istream_iterator&, const istream_iterator&);#endif /* __STL_MEMBER_TEMPLATES */protected: istream* _M_stream; _Tp _M_value; bool _M_end_marker; void _M_read() { _M_end_marker = (*_M_stream) ? true : false; if (_M_end_marker) *_M_stream >> _M_value; _M_end_marker = (*_M_stream) ? true : false; }public: typedef input_iterator_tag iterator_category; typedef _Tp value_type; typedef _Dist difference_type; typedef const _Tp* pointer; typedef const _Tp& reference; istream_iterator() : _M_stream(&cin), _M_end_marker(false) {} istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); } reference operator*() const { return _M_value; }#ifndef __SGI_STL_NO_ARROW_OPERATOR pointer operator->() const { return &(operator*()); }#endif /* __SGI_STL_NO_ARROW_OPERATOR */ istream_iterator<_Tp, _Dist>& operator++() { _M_read(); return *this; } istream_iterator<_Tp, _Dist> operator++(int) { istream_iterator<_Tp, _Dist> __tmp = *this; _M_read(); return __tmp; }};#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _Tp, class _Dist>inline input_iterator_tag iterator_category(const istream_iterator<_Tp, _Dist>&){ return input_iterator_tag();}template <class _Tp, class _Dist>inline _Tp* value_type(const istream_iterator<_Tp, _Dist>&) { return (_Tp*) 0; }template <class _Tp, class _Dist>inline _Dist* distance_type(const istream_iterator<_Tp, _Dist>&) { return (_Dist*)0; }#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */template <class _Tp, class _Distance>inline bool operator==(const istream_iterator<_Tp, _Distance>& __x, const istream_iterator<_Tp, _Distance>& __y) { return (__x._M_stream == __y._M_stream && __x._M_end_marker == __y._M_end_marker) || __x._M_end_marker == false && __y._M_end_marker == false;}#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDERtemplate <class _Tp, class _Distance>inline bool operator!=(const istream_iterator<_Tp, _Distance>& __x, const istream_iterator<_Tp, _Distance>& __y) { return !(__x == __y);}#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */template <class _Tp>class ostream_iterator {protected: ostream* _M_stream; const char* _M_string;public: typedef output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {} ostream_iterator(ostream& __s, const char* __c) : _M_stream(&__s), _M_string(__c) {} ostream_iterator<_Tp>& operator=(const _Tp& __value) { *_M_stream << __value; if (_M_string) *_M_stream << _M_string; return *this; } ostream_iterator<_Tp>& operator*() { return *this; } ostream_iterator<_Tp>& operator++() { return *this; } ostream_iterator<_Tp>& operator++(int) { return *this; } };#ifndef __STL_CLASS_PARTIAL_SPECIALIZATIONtemplate <class _Tp>inline output_iterator_tag iterator_category(const ostream_iterator<_Tp>&) { return output_iterator_tag();}#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */#endif /* __STL_USE_NEW_IOSTREAMS */// This iterator adapter is 'normal' in the sense that it does not// change the semantics of any of the operators of its itererator// parameter. Its primary purpose is to convert an iterator that is// not a class, e.g. a pointer, into an iterator that is a class.// The _Container parameter exists solely so that different containers// using this template can instantiate different types, even if the// _Iterator parameter is the same.template<typename _Iterator, typename _Container>class __normal_iterator : public iterator<iterator_traits<_Iterator>::iterator_category, iterator_traits<_Iterator>::value_type, iterator_traits<_Iterator>::difference_type, iterator_traits<_Iterator>::pointer, iterator_traits<_Iterator>::reference>{public: typedef __normal_iterator<_Iterator, _Container> normal_iterator_type; inline __normal_iterator() : _M_current() { } inline explicit __normal_iterator(const _Iterator& __i) : _M_current(__i) { } // Allow iterator to const_iterator conversion template<typename _Iter> inline __normal_iterator(const __normal_iterator<_Iter, _Container>& __i) : _M_current(__i.base()) { } // forward iterator requirements inline reference operator*() const { return *_M_current; } inline pointer operator->() const { return _M_current; } inline normal_iterator_type& operator++() { ++_M_current; return *this; } inline normal_iterator_type operator++(int) { return __normal_iterator(_M_current++); } // bidirectional iterator requirements inline normal_iterator_type& operator--() { --_M_current; return *this; } inline normal_iterator_type operator--(int) { return __normal_iterator(_M_current--); } // random access iterator requirements inline reference operator[](const difference_type& __n) const { return _M_current[__n]; } inline normal_iterator_type& operator+=(const difference_type& __n) { _M_current += __n; return *this; } inline normal_iterator_type operator+(const difference_type& __n) const { return __normal_iterator(_M_current + __n); } inline normal_iterator_type& operator-=(const difference_type& __n) { _M_current -= __n; return *this; } inline normal_iterator_type operator-(const difference_type& __n) const { return __normal_iterator(_M_current - __n); } inline difference_type operator-(const normal_iterator_type& __i) const { return _M_current - __i._M_current; } const _Iterator& base() const { return _M_current; }protected: _Iterator _M_current;};// forward iterator requirementstemplate<typename _IteratorL, typename _IteratorR, typename _Container>bool operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return __lhs.base() == __rhs.base(); }template<typename _IteratorL, typename _IteratorR, typename _Container>bool operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return !(__lhs == __rhs); }// random access iterator requirementstemplate<typename _IteratorL, typename _IteratorR, typename _Container>bool operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return __lhs.base() < __rhs.base(); }template<typename _IteratorL, typename _IteratorR, typename _Container>bool operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return __rhs < __lhs; }template<typename _IteratorL, typename _IteratorR, typename _Container>bool operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return !(__rhs < __lhs); }template<typename _IteratorL, typename _IteratorR, typename _Container>bool operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return !(__lhs < __rhs); }template<typename _Iterator, typename _Container>inline __normal_iterator<_Iterator, _Container>operator+(__normal_iterator<_Iterator, _Container>::difference_type __n, const __normal_iterator<_Iterator, _Container>& __i){ return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }__STL_END_NAMESPACE#endif /* __SGI_STL_INTERNAL_ITERATOR_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -