Cromon

vector

Oct 24th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. _Myt& operator=(const _Myt& _Right)
  2. { // assign _Right
  3. if (this != &_Right)
  4. { // different, assign it
  5. #if _HAS_CPP0X
  6. if (this->_Getal() != _Right._Getal()
  7. && _Alty::propagate_on_container_copy_assignment::value)
  8. { // change allocator before copying
  9. _Tidy();
  10. this->_Change_alloc(_Right._Getal());
  11. }
  12. #endif /* _HAS_CPP0X */
  13.  
  14. this->_Orphan_all();
  15.  
  16. if (_Right.empty())
  17. clear(); // new sequence empty, erase existing sequence
  18. else if (_Right.size() <= size())
  19. { // enough elements, copy new and destroy old
  20. pointer _Ptr = _Copy_impl(_Right._Myfirst,
  21. _Right._Mylast, this->_Myfirst); // copy new
  22. _Destroy(_Ptr, this->_Mylast); // destroy old
  23. this->_Mylast = this->_Myfirst + _Right.size();
  24. }
  25. else if (_Right.size() <= capacity())
  26. { // enough room, copy and construct new
  27. pointer _Ptr = _Right._Myfirst + size();
  28. _Copy_impl(_Right._Myfirst,
  29. _Ptr, this->_Myfirst);
  30. this->_Mylast = _Ucopy(_Ptr, _Right._Mylast, this->_Mylast);
  31. }
  32. else
  33. { // not enough room, allocate new array and construct new
  34. if (this->_Myfirst != pointer())
  35. { // discard old array
  36. _Destroy(this->_Myfirst, this->_Mylast);
  37. this->_Getal().deallocate(this->_Myfirst,
  38. this->_Myend - this->_Myfirst);
  39. }
  40. if (_Buy(_Right.size()))
  41. _TRY_BEGIN
  42. this->_Mylast = _Ucopy(_Right._Myfirst, _Right._Mylast,
  43. this->_Myfirst);
  44. _CATCH_ALL
  45. _Tidy();
  46. _RERAISE;
  47. _CATCH_END
  48. }
  49. }
  50. return (*this);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment