stl_iterator.h
来自「ARM Linux Tool 各种代码包括MTD」· C头文件 代码 · 共 549 行 · 第 1/2 页
H
549 行
template <class _Iterator>inline bool operator!=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x == __y);}template <class _Iterator>inline bool operator>(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y < __x;}template <class _Iterator>inline bool operator<=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__y < __x);}template <class _Iterator>inline bool operator>=(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return !(__x < __y);}template <class _Iterator>inline typename reverse_iterator<_Iterator>::difference_typeoperator-(const reverse_iterator<_Iterator>& __x, const reverse_iterator<_Iterator>& __y) { return __y.base() - __x.base();}template <class _Iterator>inline reverse_iterator<_Iterator> operator+(typename reverse_iterator<_Iterator>::difference_type __n, const reverse_iterator<_Iterator>& __x) { return reverse_iterator<_Iterator>(__x.base() - __n);}template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT>, class _Dist = ptrdiff_t> class istream_iterator {public: typedef _CharT char_type; typedef _Traits traits_type; typedef basic_istream<_CharT, _Traits> istream_type; 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(0), _M_ok(false) {} istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); } reference operator*() const { return _M_value; } pointer operator->() const { return &(operator*()); } istream_iterator& operator++() { _M_read(); return *this; } istream_iterator operator++(int) { istream_iterator __tmp = *this; _M_read(); return __tmp; } bool _M_equal(const istream_iterator& __x) const { return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); }private: istream_type* _M_stream; _Tp _M_value; bool _M_ok; void _M_read() { _M_ok = (_M_stream && *_M_stream) ? true : false; if (_M_ok) { *_M_stream >> _M_value; _M_ok = *_M_stream ? true : false; } }};template <class _Tp, class _CharT, class _Traits, class _Dist>inline bool operator==(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x, const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) { return __x._M_equal(__y);}template <class _Tp, class _CharT, class _Traits, class _Dist>inline bool operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __x, const istream_iterator<_Tp, _CharT, _Traits, _Dist>& __y) { return !__x._M_equal(__y);}template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >class ostream_iterator {public: typedef _CharT char_type; typedef _Traits traits_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; ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {} ostream_iterator(ostream_type& __s, const _CharT* __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; } private: ostream_type* _M_stream; const _CharT* _M_string;};// 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>{protected: _Iterator _M_current;public: typedef __normal_iterator<_Iterator, _Container> normal_iterator_type; typedef iterator_traits<_Iterator> __traits_type; typedef typename __traits_type::iterator_category iterator_category; typedef typename __traits_type::value_type value_type; typedef typename __traits_type::difference_type difference_type; typedef typename __traits_type::pointer pointer; typedef typename __traits_type::reference reference; __normal_iterator() : _M_current(_Iterator()) { } 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 reference operator*() const { return *_M_current; } pointer operator->() const { return _M_current; } normal_iterator_type& operator++() { ++_M_current; return *this; } normal_iterator_type operator++(int) { return __normal_iterator(_M_current++); } // Bidirectional iterator requirements normal_iterator_type& operator--() { --_M_current; return *this; } normal_iterator_type operator--(int) { return __normal_iterator(_M_current--); } // Random access iterator requirements reference operator[](const difference_type& __n) const { return _M_current[__n]; } normal_iterator_type& operator+=(const difference_type& __n) { _M_current += __n; return *this; } normal_iterator_type operator+(const difference_type& __n) const { return __normal_iterator(_M_current + __n); } normal_iterator_type& operator-=(const difference_type& __n) { _M_current -= __n; return *this; } normal_iterator_type operator-(const difference_type& __n) const { return __normal_iterator(_M_current - __n); } difference_type operator-(const normal_iterator_type& __i) const { return _M_current - __i._M_current; } const _Iterator& base() const { return _M_current; }};// forward iterator requirementstemplate<typename _IteratorL, typename _IteratorR, typename _Container>inline booloperator==(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return __lhs.base() == __rhs.base(); }template<typename _IteratorL, typename _IteratorR, typename _Container>inline booloperator!=(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>inline 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>inline booloperator>(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return __rhs < __lhs; }template<typename _IteratorL, typename _IteratorR, typename _Container>inline booloperator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, const __normal_iterator<_IteratorR, _Container>& __rhs){ return !(__rhs < __lhs); }template<typename _IteratorL, typename _IteratorR, typename _Container>inline booloperator>=(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); }} // namespace std#endif /* __SGI_STL_INTERNAL_ITERATOR_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?