A typical template function specialization definition looks something like this:
class Foo {
[...]
};
namespace std {
template<>
void swap(Foo& left, Foo& right) {
[...]
}
}
But how do you correctly define specialization when the type it specializes in is itself a template? Here is what I have:
template <size_t Bits>
class fixed {
[...]
};
namespace std {
template<size_t Bits>
void swap(fixed<Bits>& left, fixed<Bits>& right) {
[...]
}
}
Is this right to declare swap? It should be a specialization of the template function std::swap, but I cannot say if the compiler sees it as such or thinks it overloads it or something like that.
source
share