Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. class iterator {
  2. private:
  3. Trit data;
  4. size_t current_index;
  5. TritList& list;
  6. public:
  7. explicit iterator(TritList& _list, size_t beginning_ind = 0) : list(_list) {
  8. current_index = beginning_ind;
  9. data = list[0];
  10. }
  11.  
  12. iterator(const iterator& other) : list(other.list), current_index(other.current_index), data(other.data) { }
  13. class iterator &operator++() {
  14. current_index++;
  15. data = list[current_index];
  16. return *this;
  17. }
  18. class iterator operator++(int) {
  19. iterator yu(*this);
  20. operator++();
  21. return yu;
  22. }
  23. class iterator &operator--() {
  24. current_index--;
  25. data = list[current_index];
  26. return *this;
  27. }
  28. class iterator operator--(int) {
  29. iterator yu(*this);
  30. operator--();
  31. return yu;
  32. }
  33. bool operator==(const iterator& other) const {
  34. return (other.current_index == current_index) && (other.data == data);
  35. }
  36. bool operator!=(const iterator& other) const {
  37. return !(*this == other);
  38. }
  39. const Trit &operator*() {
  40. return list[current_index];
  41. }
  42. };
  43.  
  44. iterator begin() {
  45. iterator tmp(*this);
  46. return tmp;
  47. }
  48. iterator end() {
  49. iterator tmp(*this, capacity());
  50. return tmp;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement