e.g,
vector<int> a, b; //two vector objects not allocated by new, you CANNOT assume users always use new, e.g. vector<int> * a = new vector<int>, right?
What if users want to swap the contents of a and b now? Can you do this?
vector<int>* aptr = &a;
vector<int>* bptr = &b;
then swap aptr and bptr?
No, swap pointer doesn't fit the requirement here. It is useful in many cases, as you mentioned, and can do the same job as swap in certain situations, but it cannot replace swap.
The global swap function in namespace std, std::swap(vector& a, vector& b) is based on the member function swap of vector. std::swap(a,b) is translated into a.swap(b). It's quite common in the standard library code.
vector<int> a, b; //two vector objects not allocated by new, you CANNOT assume users always use new, e.g. vector<int> * a = new vector<int>, right?
What if users want to swap the contents of a and b now? Can you do this?
vector<int>* aptr = &a;
vector<int>* bptr = &b;
then swap aptr and bptr?
No, swap pointer doesn't fit the requirement here. It is useful in many cases, as you mentioned, and can do the same job as swap in certain situations, but it cannot replace swap.
The global swap function in namespace std, std::swap(vector& a, vector& b) is based on the member function swap of vector. std::swap(a,b) is translated into a.swap(b). It's quite common in the standard library code.