| 530 | } |
| 531 | |
| 532 | iterator insert(const_iterator pos, I *const & item) |
| 533 | { |
| 534 | auto root = static_cast<L *>(this); |
| 535 | CHECK_INVALID_ARGUMENT(pos.iter.root == root); |
| 536 | |
| 537 | auto link = pos.iter.cur; |
| 538 | if (!link || !link->prev) |
| 539 | { |
| 540 | if (!link && root->next) |
| 541 | { |
| 542 | pos--; |
| 543 | return insert_after(pos, item); |
| 544 | } |
| 545 | |
| 546 | CHECK_INVALID_ARGUMENT(root->next == link); |
| 547 | push_front(item); |
| 548 | return begin(); |
| 549 | } |
| 550 | |
| 551 | auto newlink = new L(); |
| 552 | newlink->prev = link->prev; |
| 553 | newlink->next = link; |
| 554 | link->prev = newlink; |
| 555 | if (newlink->prev) |
| 556 | { |
| 557 | newlink->prev->next = newlink; |
| 558 | } |
| 559 | else if (link == root->next) |
| 560 | { |
| 561 | root->next = newlink; |
| 562 | } |
| 563 | newlink->item = item; |
| 564 | item->dfhack_set_list_link(newlink); |
| 565 | |
| 566 | return iterator(root, newlink); |
| 567 | } |
| 568 | |
| 569 | iterator insert_after(const_iterator pos, I *const & item) |
| 570 | { |