   vector::assign
  Does vector::assign(first, last) guarantee not to change the vector's capacity, provided it is large enough for the assignment?std::vector<TCHAR> vec(32768);vec.assign(str.begin(), str.end());Is vec guaranteed to still have at least 32768 TCHARs as capacity? Or could the assignment have made it smaller?   
  Is str guaranteed to be smaller than the size of 32768? If so, then that assignment should not make it smaller, nor should it make it larger.   ;  I think it's equivalent to:vec.clear();std::copy(str.begin(), str.end(), std::back_insert_iterator(vec));so the new size will be "std::distance(str.begin(), str.end())" elements.When you say 'capacity', are you talking about the value returned by vec.size() or by vec.capacity()?AFAIK, the standard doesn't make many (any?) guarantees about how reserve/capacity behave, but the behaviour of resize/size is well defined.   ;Quote:Original post by Hodgmanso the new size will beI'm talking about capacity, not size ;)   ;  The capacity is not affected, as I said earlier.By the way, Hodgman, it's equivalent to:vec.erase();std::copy(str.begin(), str.end(), std::back_insert_iterator(vec));This is the key difference.   ;  Actually, it's equivalent to:erase(begin(), end());insert(begin(), str.begin(), str.end());insert() is very different from copy() with a back_inserter.   ;Quote:insert(begin(), str.begin(), str.end());insert() is very different from copy() with a back_inserter.How is inserting element per element very different from inserting a range directly?It's not like std::vector<T>::assign provided strong exception safety...   ;Quote:Original post by loufoqueHow is inserting element per element very different from inserting a range directly?Because the range insert() operation with random access iterator inputs will resize the vector at most once. With consecutive push_back() calls, the vector can be resized multiple times.   ;Quote:Original post by SiCraneBecause the range insert() operation with random access iterator inputs will resize the vector at most once. With consecutive push_back() calls, the vector can be resized multiple times.But why isn't it resized then? I've tested with GCC/MSVC and both of them do not modify the capacity.;Quote:Original post by Halifax2But why isn't it resized then? I've tested with GCC/MSVC and both of them do not modify the capacity.Tested what exactly?