Copy algorithm usage: 1) copy v2 to v1. 2) it use loop inside. Almostall uses of copy where the destination range is specified usingan insert iterator should be replaced with calls to rangemember function.
A good example to explain why use range member function is below: When
you use insert, inside of insert, STL will get distance(n elements) of
v2,begin() and v2.end(). Then , It will reserve and move the all element in
v1 just once according to the distance. If you use copy, it use loop insert
one by one, It will move all element in v1 n times. if no space, it
will reallocate and copy old element, just like common vector do.
So use range member function, can save you a lot of time in this
example.
The main reason for using assign is to copy data from one type of container
to another.
For example, if you want to migrate the contents of an
std::set<int> to an std::vector<int>, you can’t use the
assignment operator, but you can use vector.assign(set.begin(),
set.end()).
Another example would be copying the contents of two
containers holding different types that are convertible to one
or the other; If you try to assign std::vector<Derived*> to an
std::vector<Base*>, the assignment operator is insufficient.