jeudi 24 décembre 2015

Copy-and-Swap idiom explicit template class with void gives error

Given template class Foo<T>:

template<class T>
class Foo
{
    public:
        friend void swap(Foo<T> &aFirst, Foo<T> &aSecond)
        {
            using std::swap;

            ...
        }
 }

And explicit template class Foo<void>

template<>
class Foo<void>
{
    public:
        friend void swap(Foo<void> &aFirst, Foo<void> &aSecond)
        {
            using std::swap;

            ...
        }
 }

While using the swap function inside the explicit template class Foo<void> my compiler generates the following error:

more than one instance of function "swap" matches the argument list

Is there any way to resolve this? I need to explicit define the void variant because there needs to be different behaviour.

EDIT

Example usage:

Foo(Foo<void> &&aOther) noexcept :
    Foo{}
{
    swap(*this, aOther);
}

Aucun commentaire:

Enregistrer un commentaire