1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #pragma once namespace xcg { struct input_iterator_tag {}; struct output_iterator_tag {}; struct forward_iterator_tag : public input_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {}; using ptrdiff_t = int;
template<class _C, class _Ty, class _D = ptrdiff_t, class _Pointer = _Ty*, class _Reference = _Ty&> struct iterator { typedef _C iterator_category; typedef _Ty value_type; typedef _D difference_type; typedef _Pointer pointer; typedef _Reference reference; };
template<class _Iterator> struct iterator_traits { iterator_traits() {} typedef typename _Iterator::iterator_category iterator_category; typedef typename _Iterator::value_type value_type; typedef typename _Iterator::difference_type difference_type; typedef typename _Iterator::pointer pointer; typedef typename _Iterator::reference reference; };
template<class T> struct iterator_traits<T*> { iterator_traits() {} typedef typename random_access_iterator_tag iterator_category; typedef typename T value_type; typedef typename int difference_type; typedef typename T* pointer; typedef typename T& reference; }; template<class T> struct iterator_traits<const T*> { iterator_traits() {} typedef typename random_access_iterator_tag iterator_category; typedef typename T value_type; typedef typename int difference_type; typedef typename const T* pointer; typedef typename const T& reference; };
template<class _Ty, class _D = ptrdiff_t> struct _Forit : public iterator<forward_iterator_tag, _Ty, _D> {}; template<class _Ty, class _D = ptrdiff_t> struct _Bidit : public iterator<bidirectional_iterator_tag, _Ty, _D> {}; template<class _Ty, class _D = ptrdiff_t> struct _Ranit : public iterator<random_access_iterator_tag, _Ty, _D> {};
template<class _II, class _D> inline void __advance(_II& i, _D n, input_iterator_tag) { while (n--) ++i; } template<class _BI, class _D> inline void __advance(_BI& i, _D n, bidirectional_iterator_tag) { if (n >= 0) { while (n--) ++i; } else { while (n++) --i; } } template<class _RAI, class _D> inline void __advance(_RAI& i, _D n, input_iterator_tag) { i += n; } template<class _II, class _D> inline void advance(_II& i, _D n) { iterator_traits<_II>(); typedef typename iterator_traits<_II>::iterator_category cate; __advance(i, n, cate()); } }
|