ReverseIterator.Container.tlh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #include "ReverseIterator.Base.tlh"
  3. #include "ReverseIterator.Random.tlh"
  4. //-----------------------------------------------------------------------------
  5. // Iterator
  6. // 一般容器 - 常量
  7. //-----------------------------------------------------------------------------
  8. namespace ReverseIterator
  9. {
  10. template <typename _Container>
  11. class __ConstIterator : public __RandomIterator <typename _Container::const_reverse_iterator>
  12. {
  13. typedef __RandomIterator <typename _Container::const_reverse_iterator> inherited;
  14. public:
  15. // using value_type = _Container.value_type;
  16. using reference = typename _Container::reference;
  17. using const_reference = typename _Container::const_reference;
  18. public:
  19. // 构造一个全空的迭代器, 用于容器指针为空的情形
  20. __ConstIterator () : inherited ()
  21. {
  22. }
  23. __ConstIterator (const _Container & ar)
  24. {
  25. Iter = _begin = ar.crbegin ();
  26. _end = ar.crend ();
  27. m_Count = (int) ar.size ();
  28. m_Index = m_Count - 1;
  29. }
  30. __ConstIterator (const __ConstIterator & from)
  31. {
  32. CopyAssign (from);
  33. }
  34. __ConstIterator (__ConstIterator && from)
  35. {
  36. MoveAssign (from);
  37. }
  38. ~__ConstIterator () {}
  39. public:
  40. inline __ConstIterator & operator = (const __ConstIterator & from)
  41. {
  42. CopyAssign (from);
  43. return (*this);
  44. }
  45. public:
  46. inline const_reference Current ()
  47. {
  48. return (*Iter);
  49. }
  50. inline const_reference operator () (void) { return Current (); }
  51. inline const_reference operator * (void) { return Current (); }
  52. };
  53. };
  54. //-----------------------------------------------------------------------------
  55. // Iterator
  56. // 一般容器 - 变量
  57. //-----------------------------------------------------------------------------
  58. namespace ReverseIterator
  59. {
  60. template <typename _Container>
  61. class __Iterator : public __RandomIterator <typename _Container::reverse_iterator>
  62. {
  63. typedef __RandomIterator <typename _Container::reverse_iterator> inherited;
  64. public:
  65. // using value_type = _Container.value_type;
  66. using reference = typename _Container::reference;
  67. public:
  68. // 构造一个全空的迭代器, 用于容器指针为空的情形
  69. __Iterator () : inherited ()
  70. {
  71. }
  72. __Iterator (_Container & ar)
  73. {
  74. Iter = _begin = ar.rbegin ();
  75. _end = ar.rend ();
  76. m_Count = (int) ar.size ();
  77. m_Index = m_Count - 1;
  78. }
  79. __Iterator (const __Iterator & from)
  80. {
  81. CopyAssign (from);
  82. }
  83. __Iterator (__Iterator && from)
  84. {
  85. MoveAssign (from);
  86. }
  87. ~__Iterator () {}
  88. public:
  89. inline __Iterator & operator = (const __Iterator & from)
  90. {
  91. CopyAssign (from);
  92. return (*this);
  93. }
  94. public:
  95. inline reference Current ()
  96. {
  97. return (*Iter);
  98. }
  99. inline reference operator () (void) { return Current (); }
  100. inline reference operator * (void) { return Current (); }
  101. };
  102. }