Is there a difference between the following approaches?
// approach 1
namespace std
{
template<>
void swap<Foo>(Foo& x, Foo& y) // note the <Foo>
{
x.swap(y);
}
}
// approach 2
namespace std
{
template<>
void swap(Foo& x, Foo& y)
{
x.swap(y);
}
}
I stumpled upon this when I tried to specialize swap for my own string type and noticed that swap<::string> doesn’t work, but for a completely different reason 🙂
Yes, there is. But not in that particular example. If the parameter is not deduced, it can make a difference
You cannot specialize that without
<type>because it cannot deduce whatTis from the parameter list.Of course in your case, it’s the digraph
<:that’s meaning the same as[causing your problem. Put a space like<::string>to avoid the problem.