| 16 | class SparseVector { |
| 17 | public: |
| 18 | class iterator { |
| 19 | public: |
| 20 | using value_type = std::pair<size_t, ElementType>; |
| 21 | |
| 22 | iterator(const SparseVector& vector, size_t index): vector(vector), index(index) { } |
| 23 | |
| 24 | value_type operator*() const { |
| 25 | return {this->vector.indices[this->index], this->vector.values[this->index]}; |
| 26 | } |
| 27 | |
| 28 | iterator& operator++() { |
| 29 | ++this->index; |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | friend bool operator!=(const iterator& a, const iterator& b) { |
| 34 | return &a.vector != &b.vector || a.index != b.index; |
| 35 | } |
| 36 | |
| 37 | friend bool operator==(const iterator& a, const iterator& b) { |
| 38 | return &a.vector == &b.vector && a.index == b.index; |
| 39 | } |
| 40 | |
| 41 | protected: |
| 42 | const SparseVector& vector; |
| 43 | size_t index; |
| 44 | }; |
| 45 | |
| 46 | using value_type = ElementType; |
| 47 | |