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);
- }
- // Базовая гарантия безопасности исключений
- if (size_ == capacity_) {
- assert(size_ <= capacity_);
- SimpleVector tmp_vector(size_ + 1, value); // чтобы записать в нужной позиции value
- std::copy(this->cbegin(), pos, tmp_vector.begin());
- std::copy_backward(pos, this->cend(), tmp_vector.end());
- tmp_vector.capacity_ = size_ * 2;
- size_t position_insert_value = std::distance(this->cbegin(), pos);
- this->swap(tmp_vector);
- //std::cout << "Insert(): " << simple_vector_[position_insert_value] << '\t' << value << std::endl;
- return Iterator (&simple_vector_[position_insert_value]);
- } else {
- std::copy_backward(pos, this->cend(), std::next(this->end()));
- std::copy(&value, &value + 1, const_cast<Iterator>(pos));
- ++size_;
- //std::cout << "Insert(): " << *pos << '\t' << value << std::endl;
- return const_cast<Iterator>(pos);
- }
- //// Стогая гарантия безопасности исключений
- //SimpleVector tmp_vector(size_ + 1, value); // чтобы записать в нужной позиции value
- //std::copy(this->cbegin(), pos, tmp_vector.begin());
- //std::copy_backward(pos, this->cend(), tmp_vector.end());
- //this->swap(tmp_vector);
- //return const_cast<Iterator> (pos);
- }
Add Comment
Please, Sign In to add comment