Couple of questions on boost::swap
. Please refer to the code below which is basically a cut-paste from boost/swap.hpp
. I am referring to library version 1.43.0.
namespace boost_swap_impl
{
template<class T>
void swap_impl(T& left, T& right)
{
using namespace std;//use std::swap if argument dependent lookup fails
swap(left,right);
}
template<class T, std::size_t N>
void swap_impl(T (& left)[N], T (& right)[N])
{
for (std::size_t i = 0; i < N; ++i)
{
::boost_swap_impl::swap_impl(left[i], right[i]);
}
}
}
namespace boost
{
template<class T1, class T2>
void swap(T1& left, T2& right)
{
::boost_swap_impl::swap_impl(left, right);
}
}
- Why is
boost::swap
declared astemplate <typename T1, typename T2>
when in the rest of the code it is all dealing with the same type? - If I define my own global function
void swap(T&, T&)
I see that it is the global function that gets called fromswap_impl(T& left, T& right)
. Is this not a conflict and hence an error condition sinceswap_impl
also usesnamespace std
which has swap defined?