c/c++ 關於swap的不同寫法

OpenSoucre發表於2013-07-25

利用模板

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;})

 

相關文章