Here I write a code snippet to see which swap
would be called, but the result is neither. Nothing is outputted.
#include<iostream>
class Test {};
void swap(const Test&lhs,const Test&rhs)
{
std::cout << "1";
}
namespace std
{
template<>
void swap(const Test&lhs, const Test&rhs)
{
std::cout << "2";
}
/* If I remove the const specifier,then this will be called,but still not the one in global namespace,why?
template<>
void swap(Test&lhs, Test&rhs)
{
std::cout << "2";
}
*/
}
using namespace std;
int main()
{
Test a, b;
swap(a, b);//Nothing outputed
return 0;
}
Which swap
is called? And in another circumstance, why is the specialized swap
without const
specifier called, not the ::swap
?