intrusive_iterator.tpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // intrusive_iterator.hpp
  3. // utilities
  4. //
  5. // Created by Sam Jaffe on 5/10/13.
  6. // Copyright (c) 2013 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include "intrusive_iterator.hpp"
  10. template <typename N>
  11. intrusive_iterator<N>::intrusive_iterator(N* node) :
  12. node_(node) {
  13. }
  14. template <typename N>
  15. intrusive_iterator<N>::operator const_intrusive_iterator<N>() const {
  16. return node_;
  17. }
  18. template <typename N>
  19. auto intrusive_iterator<N>::operator*() -> reference {
  20. return *(node_->ptr_);
  21. }
  22. template <typename N>
  23. auto intrusive_iterator<N>::operator*() const -> const_reference {
  24. return *(node_->ptr_);
  25. }
  26. template <typename N>
  27. auto intrusive_iterator<N>::operator->() -> pointer {
  28. return node_->ptr_;
  29. }
  30. template <typename N>
  31. auto intrusive_iterator<N>::operator->() const -> const_pointer {
  32. return node_->ptr_;
  33. }
  34. template <typename N>
  35. intrusive_iterator<N> intrusive_iterator<N>::operator++(int) {
  36. intrusive_iterator<N> it{*this};
  37. node_ = node_->next_;
  38. return it;
  39. }
  40. template <typename N>
  41. intrusive_iterator<N>& intrusive_iterator<N>::operator++() {
  42. node_ = node_->next_;
  43. return *this;
  44. }
  45. template <typename N>
  46. intrusive_iterator<N> intrusive_iterator<N>::operator--(int) {
  47. intrusive_iterator<N> it{*this};
  48. node_ = node_->prev_;
  49. return it;
  50. }
  51. template <typename N>
  52. intrusive_iterator<N>& intrusive_iterator<N>::operator--() {
  53. node_ = node_->prev_;
  54. return *this;
  55. }
  56. template <typename N>
  57. N* intrusive_iterator<N>::get() const {
  58. return node_;
  59. }
  60. template <typename N>
  61. bool intrusive_iterator<N>::operator==(const intrusive_iterator<N>& other) const {
  62. return node_ == other.node_;
  63. }
  64. template <typename N>
  65. bool intrusive_iterator<N>::operator!=(const intrusive_iterator<N>& other) const {
  66. return node_ != other.node_;
  67. }
  68. #pragma mark const_intrusive_iterator
  69. template <typename N>
  70. const_intrusive_iterator<N>::const_intrusive_iterator(N* node) :
  71. node_(node) {
  72. }
  73. template <typename N>
  74. auto const_intrusive_iterator<N>::operator*() const -> const_reference {
  75. return *(node_->ptr_);
  76. }
  77. template <typename N>
  78. auto const_intrusive_iterator<N>::operator->() const -> const_pointer {
  79. return node_->ptr_;
  80. }
  81. template <typename N>
  82. const_intrusive_iterator<N> const_intrusive_iterator<N>::operator++(int) {
  83. const_intrusive_iterator<N> it{*this};
  84. node_ = node_->next_;
  85. return it;
  86. }
  87. template <typename N>
  88. const_intrusive_iterator<N>& const_intrusive_iterator<N>::operator++() {
  89. node_ = node_->next_;
  90. return *this;
  91. }
  92. template <typename N>
  93. const_intrusive_iterator<N> const_intrusive_iterator<N>::operator--(int) {
  94. const_intrusive_iterator<N> it{*this};
  95. node_ = node_->prev_;
  96. return it;
  97. }
  98. template <typename N>
  99. const_intrusive_iterator<N>& const_intrusive_iterator<N>::operator--() {
  100. node_ = node_->prev_;
  101. return *this;
  102. }
  103. template <typename N>
  104. N* const_intrusive_iterator<N>::get() const {
  105. return node_;
  106. }
  107. template <typename N>
  108. bool const_intrusive_iterator<N>::operator==(const const_intrusive_iterator<N>& other) const {
  109. return node_ == other.node_;
  110. }
  111. template <typename N>
  112. bool const_intrusive_iterator<N>::operator!=(const const_intrusive_iterator<N>& other) const {
  113. return node_ != other.node_;
  114. }