You have two very similar overloads for operator+
, originally without the template
template <int = 0>
constexpr year_month operator+(const year_month& _Left, const months& _Right) noexcept
constexpr year_month operator+(const year_month& _Left, const years& _Right) noexcept
It was discovered that if you have a value that is convertible to both months
and years
, there was an ambiguity here. Which conversion should be chosen?
By making one of the operators (a dummy) template, the non-template is chosen (if possible) because templates have lower priority in overload resolution.
The standard specifies this requirement a bit convoluted (backwards in my opinion):
"If the argument supplied by the caller for the months parameter is convertible to years, its implicit conversion sequence to years is worse than its implicit conversion sequence to months"
So if the conversions are equally good, the non-template is to be chosen. Only if conversion to months is better, the template gets a chance.
(And the standard doesn't explicitly say that is has to be a template, but that is a way of implementing this requirement).
auto x = operator+<0>(ym, m);