J
Julie
Ioannis said:A decent swap function should perform a value equality check both for
safety and run-time efficiency, especially when this does not impose any
space/time concerns, perhaps in the style:
This is purely subjective. Stating preconditions in the functional interface
description is perfectly appropriate.
Sanity checks can be implemented when/where warranted, but mostly serve to
verify that the user is obeying the preconditions.
template<class T>
void swap(T &a, T &b)
{
if(a!=b)
{
// ...
}
}
In any case, we should stick with std::swap and provide specialisations
when necessary.
Yeah, yeah, but that isn't what we are talking about.