Changeset 8a7da64d in mainline
- Timestamp:
- 2018-07-05T21:41:22Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 255bb63
- Parents:
- e8ebed9
- git-author:
- Dzejrou <dzejrou@…> (2018-05-01 20:56:29)
- git-committer:
- Dzejrou <dzejrou@…> (2018-07-05 21:41:22)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/map.hpp
re8ebed9 r8a7da64d 358 358 } 359 359 360 // TODO: try_emplace, insert_or_assign 360 template<class... Args> 361 pair<iterator, bool> try_emplace(const key_type& key, Args&&... args) 362 { 363 auto parent = tree_.find_parent_for_insertion(key); 364 if (parent && tree_.keys_equal(tree_.get_key(parent->value), key)) 365 return make_pair(iterator{parent, false}, false); 366 else 367 { 368 auto node = new node_type{value_type{key, forward<Args>(args)...}}; 369 tree_.insert_node(node, parent); 370 371 return make_pair(iterator{node, false}, true); 372 } 373 } 374 375 template<class... Args> 376 pair<iterator, bool> try_emplace(key_type&& key, Args&&... args) 377 { 378 auto parent = tree_.find_parent_for_insertion(key); 379 if (parent && tree_.keys_equal(tree_.get_key(parent->value), key)) 380 return make_pair(iterator{parent, false}, false); 381 else 382 { 383 auto node = new node_type{value_type{move(key), forward<Args>(args)...}}; 384 tree_.insert_node(node, parent); 385 386 return make_pair(iterator{node, false}, true); 387 } 388 } 389 390 template<class... Args> 391 iterator try_emplace(const_iterator, const key_type& key, Args&&... args) 392 { 393 return try_emplace(key, forward<Args>(args)...).first; 394 } 395 396 template<class... Args> 397 iterator try_emplace(const_iterator, key_type&& key, Args&&... args) 398 { 399 return try_emplace(move(key), forward<Args>(args)...).first; 400 } 401 402 template<class T> 403 pair<iterator, bool> insert_or_assign(const key_type& key, T&& val) 404 { 405 auto parent = tree_.find_parent_for_insertion(key); 406 if (parent && tree_.keys_equal(tree_.get_key(parent->value), key)) 407 { 408 parent->value = value_type{key, forward<T>(val)}; 409 410 return make_pair(iterator{parent, false}, false); 411 } 412 else 413 { 414 auto node = new node_type{value_type{key, forward<T>(val)}}; 415 tree_.insert_node(node, parent); 416 417 return make_pair(iterator{node, false}, true); 418 } 419 } 420 421 template<class T> 422 pair<iterator, bool> insert_or_assign(key_type&& key, T&& val) 423 { 424 auto parent = tree_.find_parent_for_insertion(key); 425 if (parent && tree_.keys_equal(tree_.get_key(parent->value), key)) 426 { 427 parent->value = value_type{move(key), forward<T>(val)}; 428 429 return make_pair(iterator{parent, false}, false); 430 } 431 else 432 { 433 auto node = new node_type{value_type{move(key), forward<T>(val)}}; 434 tree_.insert_node(node, parent); 435 436 return make_pair(iterator{node, false}, true); 437 } 438 } 439 440 template<class T> 441 iterator insert_or_assign(const_iterator, const key_type& key, T&& val) 442 { 443 return insert_or_assign(key, forward<T>(val)).first; 444 } 445 446 template<class T> 447 iterator insert_or_assign(const_iterator, key_type&& key, T&& val) 448 { 449 return insert_or_assign(move(key), forward<T>(val)).first; 450 } 361 451 362 452 iterator erase(const_iterator position)
Note:
See TracChangeset
for help on using the changeset viewer.