Syntax for specializing function templates

Posted by FredOverflow on Stack Overflow See other posts from Stack Overflow or by FredOverflow
Published on 2010-04-30T20:22:37Z Indexed on 2010/04/30 20:57 UTC
Read the original article Hit count: 403

Filed under:
|
|

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 :)

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates