The usual definition for a specialization of a template function is something like this:
class Foo {
[...]
};
namespace std {
template<>
void swap(Foo& left, Foo& right) {
[...]
}
} // namespace std
But how do you properly define the specialization when the type it's specialized on is itself a template? Here's what I've got:
template <size_t Bits>
class fixed {
[...]
};
namespace std {
template<size_t Bits>
void swap(fixed<Bits>& left, fixed<Bits>& right) {
[...]
}
} // namespace std
Is this the right way to declare swap
? It's supposed to be a specialization of the template function std::swap
, but I can't tell whether the compiler is seeing it as such, or whether it thinks that it's an overload of it or something.