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

 

posted @ 2013-07-25 11:31  OpenSoucre  阅读(299)  评论(0编辑  收藏  举报