mercredi 21 janvier 2015

extending namespace std via partial template specialization

As far as I know, we are allowed (with some exceptions that I won't mention here) to "extend" namespace std by totally specializing a std template function such as std::swap, i.e.



namespace std
{
template<>
void swap<Foo>(Foo& lhs, Foo& rhs){...}
}


is perfectly valid.


Since C++11, we can now partially specialize functions. I believe that we can then play the same game and extend std via partial specialization, like



namespace std
{
template<typename T>
void swap<Foo<T>>(Foo<T>& lhs, Foo<T>& rhs){...}
}


however I am not sure about this and couldn't find the proper explaining section in the standard. Is the code immediately above correct or does it lead to UB?


PS: As @Columbo mentioned in the answer, we cannot partially specialize function templates, not even in C++11/14. For some reason I thought one can do that, I believed it was at least a proposal.


Aucun commentaire:

Enregistrer un commentaire