[C++] swap(T &a, T &b)

//#include<algorithm> to use this template

template <class T> void swap (T& a, T& b)
{
    T c(std::move(a)); a=std::move(b); b=std::move(c);
}
template <class T, size_t N> void swap (T (&a)[N], T (&b)[N])
{
    for (size_t i = 0; i<N; ++i) swap (a[i],b[i]);
}

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *