c/c++ 关于swap的不同写法

利用模板

template<typename T>inline void swap(T& a, T& b){
    T tmp = a;
    a = b;
    b = tmp;
}

利用宏定义

#define SWAP( x , y) ({__typeof__(x) temp = (x);x=y; y = temp;})
原文地址:https://www.cnblogs.com/xiongqiangcs/p/3214014.html