mardi 24 août 2021

What's the difference between =delete for templates and just using explicit?

I was reading Explicitly defaulted and deleted special member functions, and saw that in order to call only the function f with double and avoid an implicit conversion, one could write this (from the same page):

struct OnlyDouble
{
    void f(double d);
    template<class T> void f(T) = delete;
};

Is there a reason why one would write the code above instead of this code below?

struct OnlyDouble
{
    explicit void f(double d);
};

Any difference, or is there some extra behavior that I don't know of?

Aucun commentaire:

Enregistrer un commentaire