Example #1
0
 string& string::operator=(const TinySTL::string &str){
     if(this != &str){
         destroyAndDeallocate();
         allocateAndCopy(str.start_, str.finish_);
     }
     return *this;
 }
Example #2
0
	void string::resize(size_t n, char c)
	{
		if (n < size())
		{
			dataAllocator::destroy(start_ + n, finish_);
			finish_ = start_ + n;
		}
		else if (n > size() && n <= capacity())
		{
			auto lengthOfInsert = n - size();
			finish_ = mystl::uninitialized_fill_n(finish_, lengthOfInsert, c);
		}
		else if (n > capacity())
		{
			auto lengthOfInsert = n - size();
			iterator newStart = dataAllocator::allocate(getNewCapacity(lengthOfInsert));
			iterator newFinish = mystl::uninitialized_copy(begin(), end(), newStart);
			newFinish = mystl::uninitialized_fill_n(newFinish, lengthOfInsert, c);

			destroyAndDeallocate();
			start_ = newStart;
			finish_ = newFinish;
			endOfStorage_ = start_ + n;
		}
	}
Example #3
0
 void string::reserve(size_t n){
     if(n <= capacity()){
         return ;
     }
     iterator newStart = dataAllocator::allocate(n);
     iterator newFinish = std::uninitialized_copy(begin(), end(), newStart);
     destroyAndDeallocate();
     start_ = newStart;
     finish_ = newFinish;
     endOfStorage_ = start_ + n;
 }
Example #4
0
 string::iterator string::insert_aux_filln(iterator p, size_t n, value_type c){
     auto newCapacity = getNewCapacity(n);
     iterator newStart = dataAllocator::allocate(newCapacity);
     iterator newFinish = std::uninitialized_fill_n(start_, n, c);
     auto res = newFinish;
     newFinish = std::uninitialized_copy(p,finish_,newFinish);
     destroyAndDeallocate();
     start_ = newStart;
     finish_ = newFinish;
     endOfStorage_ = start_ + newCapacity;
     return res;
     
 }
Example #5
0
 string& string::operator=(const char *s){
     destroyAndDeallocate();
     allocateAndCopy(s, s+strlen(s));
     return *this;
 }
Example #6
0
 string& string::operator=(char c){
     destroyAndDeallocate();
     allocateAndFillN(1, c);
     return *this;
 }
Example #7
0
 string::~string(){
     destroyAndDeallocate();
 }