How can I define a function template to prevent implicit conversions?
It seems I can prevent implicit conversions using non-template functions but not using function
The following overload will prevent implicit conversions:
template
void no_conversions(T) = delete; // 7
void no_conversions(const B&) {} // 8
and leads to:
// Requested behaviour.
no_conversions(a); // resolves to 7
no_conversions(b); // resolves to 8
A value-overload poisons the overload set for implicit conversions as it will be an exact match.
Edit:
template
void no_conversions(const T&) = delete; // 9
void no_conversions(const B&) {} // 10
works just as well.