Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Iterator Insert(ConstIterator pos, const Type& value) {
- if (capacity_ == 0) {
- this->PushBack(value);
- return this->begin();
- }
- // Базовая гарантия безопасности исключений
- if (size_ == capacity_) {
- assert(size_ <= capacity_);
- ArrayPtr<Type> tmp_arr(capacity_ * 2);
- Iterator new_pos = std::copy(cbegin(), pos, tmp_arr.Get());
- *new_pos = value;
- std::copy_backward(pos, cend(), tmp_arr.Get() + size_ + 1);
- ++size_;
- capacity_ *= 2;
- simple_vector_.swap(tmp_arr);
- return new_pos;
- } else {
- //Iterator new_pos = std::copy_backward(pos, this->cend(), std::next(this->end()));
- //*new_pos = value;
- std::copy_backward(pos, this->cend(), std::next(this->end()));
- std::copy(&value, &value + 1, const_cast<Iterator>(pos));
- ++size_;
- return const_cast<Iterator>(pos);
- }
- }
- Iterator Insert(Iterator pos, Type&& value) {
- if (capacity_ == 0) {
- this->PushBack(std::move(value));
- return this->begin();
- }
- // Базовая гарантия безопасности исключений
- if (size_ == capacity_) {
- assert(size_ <= capacity_);
- ArrayPtr<Type> tmp_arr(capacity_ * 2);
- Iterator new_pos = std::move(begin(), pos, tmp_arr.Get());
- *new_pos = std::move(value);
- std::move_backward(new_pos, end(), tmp_arr.Get() + size_ + 1);
- ++size_;
- capacity_ *= 2;
- simple_vector_ = std::move(tmp_arr);
- return new_pos;
- } else {
- Iterator new_pos = std::move_backward(pos, this->end(), std::next(this->end()));
- *new_pos = std::move(value);
- ++size_;
- return new_pos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment