模板函数C++ utility standard header精髓
template<class _Ty> inline void swap(_Ty& _Left, _Ty& _Right) { // exchange values stored at _Left and _Right if (&_Left != &_Right) { // different, worth swapping _Ty _Tmp = _Left; _Left = _Right; _Right = _Tmp; } }
if (&_Left != &_Right)这个比较很精髓,在相同时不需要交换是可以加快效率,但是如果需要交换时会多比较一次;
思想可以学习下。。