intrusive_iterator.tpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. auto intrusive_iterator<N>::operator*() -> reference {
  16. return *(node_->ptr_);
  17. }
  18. template <typename N>
  19. auto intrusive_iterator<N>::operator*() const -> const_reference {
  20. return *(node_->ptr_);
  21. }
  22. template <typename N>
  23. auto intrusive_iterator<N>::operator->() -> pointer {
  24. return node_->ptr_;
  25. }
  26. template <typename N>
  27. auto intrusive_iterator<N>::operator->() const -> const_pointer {
  28. return node_->ptr_;
  29. }
  30. template <typename N>
  31. intrusive_iterator<N> intrusive_iterator<N>::operator++(int) {
  32. intrusive_iterator<N> it{*this};
  33. node_ = node_->next_;
  34. return it;
  35. }
  36. template <typename N>
  37. intrusive_iterator<N>& intrusive_iterator<N>::operator++() {
  38. node_ = node_->next_;
  39. return *this;
  40. }
  41. template <typename N>
  42. intrusive_iterator<N> intrusive_iterator<N>::operator--(int) {
  43. intrusive_iterator<N> it{*this};
  44. node_ = node_->prev_;
  45. return it;
  46. }
  47. template <typename N>
  48. intrusive_iterator<N>& intrusive_iterator<N>::operator--() {
  49. node_ = node_->prev_;
  50. return *this;
  51. }
  52. template <typename N>
  53. N* intrusive_iterator<N>::get() const {
  54. return node_;
  55. }
  56. template <typename N>
  57. bool intrusive_iterator<N>::operator==(const intrusive_iterator<N>& other) const {
  58. return node_ == other.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. #pragma mark const_intrusive_iterator
  65. template <typename N>
  66. const_intrusive_iterator<N>::const_intrusive_iterator(N* node) :
  67. node_(node) {
  68. }
  69. template <typename N>
  70. auto const_intrusive_iterator<N>::operator*() const -> const_reference {
  71. return *(node_->ptr_);
  72. }
  73. template <typename N>
  74. auto const_intrusive_iterator<N>::operator->() const -> const_pointer {
  75. return node_->ptr_;
  76. }
  77. template <typename N>
  78. const_intrusive_iterator<N> const_intrusive_iterator<N>::operator++(int) {
  79. const_intrusive_iterator<N> it{*this};
  80. node_ = node_->next_;
  81. return it;
  82. }
  83. template <typename N>
  84. const_intrusive_iterator<N>& const_intrusive_iterator<N>::operator++() {
  85. node_ = node_->next_;
  86. return *this;
  87. }
  88. template <typename N>
  89. const_intrusive_iterator<N> const_intrusive_iterator<N>::operator--(int) {
  90. const_intrusive_iterator<N> it{*this};
  91. node_ = node_->prev_;
  92. return it;
  93. }
  94. template <typename N>
  95. const_intrusive_iterator<N>& const_intrusive_iterator<N>::operator--() {
  96. node_ = node_->prev_;
  97. return *this;
  98. }
  99. template <typename N>
  100. N* const_intrusive_iterator<N>::get() const {
  101. return node_;
  102. }
  103. template <typename N>
  104. bool const_intrusive_iterator<N>::operator==(const const_intrusive_iterator<N>& other) const {
  105. return node_ == other.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. }