Changeset 83aea53 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:17Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b4b01cb
Parents:
b946b052
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-25 17:03:18)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:17)
Message:

cpp: fixed minor bugs in vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/vector.hpp

    rb946b052 r83aea53  
    394394                auto pos = const_cast<iterator>(position);
    395395
    396                 shift_(pos, 1);
    397                 allocator_.construct(pos, std::forward<Args>(args)...);
     396                pos = shift_(pos, 1);
     397                allocator_.construct(pos, forward<Args>(args)...);
    398398
    399399                return pos;
     
    404404                auto pos = const_cast<iterator>(position);
    405405
    406                 shift_(pos, 1);
     406                pos = shift_(pos, 1);
    407407                *pos = x;
    408408
    409                 ++size_;
    410409                return pos;
    411410            }
     
    415414                auto pos = const_cast<iterator>(position);
    416415
    417                 shift_(pos, 1);
     416                pos = shift_(pos, 1);
    418417                *pos = forward<value_type>(x);
    419418
    420                 ++size_;
    421419                return pos;
    422420            }
     
    426424                auto pos = const_cast<iterator>(position);
    427425
    428                 shift_(pos, count);
     426                pos = shift_(pos, count);
    429427                auto copy_target = pos;
    430428                for (size_type i = 0; i < count; ++i)
    431429                    *copy_target++ = x;
    432430
    433                 size_ += count;
    434431                return pos;
    435432            }
     
    442439                auto count = static_cast<size_type>(last - first);
    443440
    444                 shift_(pos, count);
    445                 std::copy(first, last, pos);
    446 
    447                 size_ += count;
     441                pos = shift_(pos, count);
     442                copy(first, last, pos);
     443
    448444                return pos;
    449445            }
     
    453449                auto pos = const_cast<iterator>(position);
    454450
    455                 shift_(pos, init.size());
    456                 std::copy(init.begin(), init.end(), pos);
    457 
    458                 size_ += init.size();
     451                pos = shift_(pos, init.size());
     452                copy(init.begin(), init.end(), pos);
     453
    459454                return pos;
    460455            }
     
    550545            }
    551546
    552             void shift_(iterator position, size_type count)
     547            iterator shift_(iterator position, size_type count)
    553548            {
    554549                if (size_ + count < capacity_)
    555                     std::copy_backwards(pos, end(), end() + count);
     550                {
     551                    copy_backward(position, end(), end() + count);
     552                    size_ += count;
     553
     554                    return position;
     555                }
    556556                else
    557557                {
     
    566566
    567567                    // Copy before insertion index.
    568                     std::copy(tmp.begin(), tmp.begin() + start_idx, begin());
     568                    copy(begin(), begin() + start_idx, tmp.begin());
    569569
    570570                    // Copy after insertion index.
    571                     std::copy(tmp.begin() + end_idx, tmp.end(), begin() + start_idx);
     571                    copy(begin() + start_idx, end(), tmp.begin() + end_idx);
    572572
    573573                    swap(tmp);
     574
     575                    // Position was invalidated!
     576                    return begin() + start_idx;
    574577                }
    575578            }
Note: See TracChangeset for help on using the changeset viewer.