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.
=========================================================
你说的user其实是C++程序员,如果我是他的leader,我要问问他为什么非要这么用!为什么不用指针。
如果我自己写template,我不提供这个swap函数,用这个vector的C++程序员根本不会产生这个想法。
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.
=========================================================
你说的user其实是C++程序员,如果我是他的leader,我要问问他为什么非要这么用!为什么不用指针。
如果我自己写template,我不提供这个swap函数,用这个vector的C++程序员根本不会产生这个想法。