Changeset 8733ce2a in mainline
- Timestamp:
- 2018-07-05T21:41:21Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f62f1ee
- Parents:
- 73066e61
- git-author:
- Dzejrou <dzejrou@…> (2018-04-20 14:47:17)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/list.hpp
r73066e61 r8733ce2a 90 90 91 91 template<class T> 92 class list_const_iterator; 92 class list_const_iterator 93 { 94 public: 95 using value_type = typename list<T>::value_type; 96 using reference = typename list<T>::const_reference; 97 98 using iterator_category = forward_iterator_tag; 99 100 list_const_iterator(list_node<value_type>* node = nullptr, 101 list_node<value_type>* head = nullptr) 102 : current_{node}, head_{head} 103 { /* DUMMY BODY */ } 104 105 list_const_iterator(const list_const_iterator&) = default; 106 list_const_iterator& operator=(const list_const_iterator&) = default; 107 list_const_iterator(list_const_iterator&&) = default; 108 list_const_iterator& operator=(list_const_iterator&&) = default; 109 110 reference operator*() const 111 { 112 return current_->value; 113 } 114 115 list_const_iterator& operator++() 116 { 117 if (current_) 118 { 119 if (current_->next == head_) 120 current_ = nullptr; 121 else 122 current_ = current_->next; 123 } 124 125 return *this; 126 } 127 128 list_const_iterator operator++(int) 129 { 130 auto bckp = current_; 131 132 if (current_) 133 { 134 if (current_->next == head_) 135 current_ = nullptr; 136 else 137 current_ = current_->next; 138 } 139 140 return list_const_iterator{bckp}; 141 } 142 143 list_node<value_type>* node() 144 { 145 return current_; 146 } 147 148 const list_node<value_type>* node() const 149 { 150 return current_; 151 } 152 153 private: 154 list_node<value_type>* current_; 155 list_node<value_type>* head_; 156 }; 157 158 template<class T> 159 bool operator==(const list_const_iterator<T>& lhs, const list_const_iterator<T>& rhs) 160 { 161 return lhs.node() == rhs.node(); 162 } 163 164 template<class T> 165 bool operator!=(const list_const_iterator<T>& lhs, const list_const_iterator<T>& rhs) 166 { 167 return !(lhs == rhs); 168 } 93 169 94 170 template<class T> … … 96 172 { 97 173 public: 98 using reference = typename list<T>::reference; 99 100 list_iterator(list_node<T>* node = nullptr) 101 : current_{node} 174 using value_type = typename list<T>::value_type; 175 using reference = typename list<T>::reference; 176 177 using iterator_category = forward_iterator_tag; 178 179 list_iterator(list_node<value_type>* node = nullptr, 180 list_node<value_type>* head = nullptr) 181 : current_{node}, head_{head} 102 182 { /* DUMMY BODY */ } 103 183 184 list_iterator(const list_iterator&) = default; 185 list_iterator& operator=(const list_iterator&) = default; 186 list_iterator(list_iterator&&) = default; 187 list_iterator& operator=(list_iterator&&) = default; 188 104 189 reference operator*() 105 190 { … … 110 195 { 111 196 if (current_) 112 current_ = current_->next; 197 { 198 if (current_->next == head_) 199 current_ = nullptr; 200 else 201 current_ = current_->next; 202 } 113 203 114 204 return *this; … … 120 210 121 211 if (current_) 122 current_ = current_->next; 212 { 213 if (current_->next == head_) 214 current_ = nullptr; 215 else 216 current_ = current_->next; 217 } 123 218 124 219 return list_iterator{bckp}; 125 220 } 126 221 127 list_iterator& operator--() 128 { 129 if (current_) 130 current_ = current_->prev; 131 132 return *this; 133 } 134 135 list_iterator operator--(int) 136 { 137 auto bckp = current_; 138 139 if (current_) 140 current_ = current_->prev; 141 142 return list_iterator{bckp}; 143 } 144 145 list_node<T>* node() 222 list_node<value_type>* node() 146 223 { 147 224 return current_; 225 } 226 227 const list_node<value_type>* node() const 228 { 229 return current_; 230 } 231 232 operator list_const_iterator<T>() const 233 { 234 return list_const_iterator{current_}; 148 235 } 149 236 150 237 private: 151 238 list_node<T>* current_; 239 list_node<value_type>* head_; 152 240 }; 153 241 154 // TODO: const iterator, iterator must be convertible to const iterator 242 template<class T> 243 bool operator==(const list_iterator<T>& lhs, const list_iterator<T>& rhs) 244 { 245 return lhs.node() == rhs.node(); 246 } 247 248 template<class T> 249 bool operator!=(const list_iterator<T>& lhs, const list_iterator<T>& rhs) 250 { 251 return !(lhs == rhs); 252 } 155 253 } 156 254 … … 316 414 iterator begin() noexcept 317 415 { 318 return iterator{head_ };416 return iterator{head_, head_}; 319 417 } 320 418 … … 326 424 iterator end() noexcept 327 425 { 328 return iterator{ };426 return iterator{nullptr, head_}; 329 427 } 330 428 … … 356 454 const_iterator cbegin() const noexcept 357 455 { 358 return const_iterator{head_ };456 return const_iterator{head_, head_}; 359 457 } 360 458 361 459 const_iterator cend() const noexcept 362 460 { 363 return const_iterator{ };461 return const_iterator{nullptr, head_}; 364 462 } 365 463 … … 510 608 } 511 609 610 template<class... Args> 611 iterator emplace(const_iterator position, Args&&... args) 612 { 613 // TODO: implement 614 } 615 512 616 /* private: */ 513 617 allocator_type allocator_;
Note:
See TracChangeset
for help on using the changeset viewer.