Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class iterator {
- private:
- Trit data;
- size_t current_index;
- TritList& list;
- public:
- explicit iterator(TritList& _list, size_t beginning_ind = 0) : list(_list) {
- current_index = beginning_ind;
- data = list[0];
- }
- iterator(const iterator& other) : list(other.list), current_index(other.current_index), data(other.data) { }
- class iterator &operator++() {
- current_index++;
- data = list[current_index];
- return *this;
- }
- class iterator operator++(int) {
- iterator yu(*this);
- operator++();
- return yu;
- }
- class iterator &operator--() {
- current_index--;
- data = list[current_index];
- return *this;
- }
- class iterator operator--(int) {
- iterator yu(*this);
- operator--();
- return yu;
- }
- bool operator==(const iterator& other) const {
- return (other.current_index == current_index) && (other.data == data);
- }
- bool operator!=(const iterator& other) const {
- return !(*this == other);
- }
- const Trit &operator*() {
- return list[current_index];
- }
- };
- iterator begin() {
- iterator tmp(*this);
- return tmp;
- }
- iterator end() {
- iterator tmp(*this, capacity());
- return tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement