Type deduction for non-viable function templates

喜欢而已 提交于 2019-12-05 18:32:56

What I've summarized is the process described at 14.8.2.1p1

Template argument deduction is done by comparing each function template parameter type (call it P) with the type of the corresponding argument of the call (call it A) as described below.

In our case, we have for P (T, int) and for A, we have (int). For the first pair of P/A, which is T against int, we can match T to int (by the process described in 14.8.2.5). But for the second "pair", we have int but have no counterpart. Thus deduction cannot be made for this "pair".

Thereby, by 14.8.2.5p2, "If type deduction cannot be done for any P/A pair, ..., template argument deduction fails.".

You then won't ever come to the point where you substitute template arguments into the function template.

This can all probably described more precisely in the Standard (IMO), but I believe this is how one could implement things to match the actual behavior of Clang and GCC and it seems a reasonable interpretation of the Standardese.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!