For a template function, we can specialize it as follows:
template <typename T>
void func(T t) {}
// specialization for int
template <>
void func(int t) {}
However, I'm not sure how to specialize a template function with universal reference (a name from Meyers' book).
// template function with universal reference
template <typename T>
void func(T &&t) {}
I think simply replacing T
with int
doesn't make it a specialization:
template <>
void func(int &&t) {}
Since the template function can accept both lvalue and rvalue, while the 'specialized' one can only accept rvalue.
Should I also define a 'specialization' with lvalue reference?
// 'specialization' for lvalue reference
template <>
void func(int &t) {}
And the two 'specializations' make the specialization for the original template function? Or does it make any sense to have a specialization for it?
Aucun commentaire:
Enregistrer un commentaire