While implementing a custom tuple
(here), I found there is a wired swap()
function that takes const
parameters (cppreference):
template< class... Types >
constexpr void swap( const std::tuple<Types...>& lhs,
const std::tuple<Types...>& rhs ) noexcept(/* see below */);
and a const-qualified swap()
member function (cppreference):
constexpr void swap( const tuple& other ) noexcept(/* see below */) const;
const
means the object is read-only, but to swap two objects, it has to modify the objects, which violates the const
-ness.
So, What's the purpose of const swap() function?