2 つの関数を定義しました。
1)。
template<class T> inline
void swap(T &first, T &second)
{
if (&first != &second)
{
T tmp = first;
first = second;
second = tmp;
}
}
2)。
template<typename T>
inline void SwapMe(T *first, T *second)
{
if(*first != *second)
{
T tmp = *first;
*first = *second;
*second = tmp;
}
}
どちらの実装が優れているか (最初の実装は std::swap() に等しい) ?