c++ - C++ DR 115: Address of template specialization even if deduction fails
问题描述
Defect Report 115 (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#115) says that if a template-id identifies a single function template specialization, it is considered to be an lvalue for that function template specialization, if template argument deduction (for the template arguments of the function template named by the template-name inside the template-id, I suppose) is not done, or it is done, but it fails.
I believe that the purpose of this defect report is to allow programs such as:
template <typename Fn>
void f(Fn param);
template <typename T>
void g(T);
int main()
{
f(g<int>);
}
This is because in the call f(g<int>)
, the type of param
(Fn
) is
a non-deduced context since its respective argument used to be (before
this defect report) a function template. This is covered by the "in
contexts where template argument deduction is not done" part of the
defect report.
What I have trouble understanding is why does the defect report also mention situations where template argument deduction is done, but fails. Why do these contexts need to be explicitly mentioned in the defect report? These situations are referred to explicitly both in [temp.arg.explicit] p. 4 and in [over.over] p. 2.
I came up with an example which may be covered by the "contexts in which template argument deduction is done, but fails" part of the defect report, however I highly doubt that this was the reason why this part was added to the defect report. The example is shown below:
template <int i>
struct B {};
template <short i = 0>
void f(B<i>);
int main()
{
void (*pf) (B<0> param);
pf = f<>();
}
In the above example template argument deduction fails because the
non-type template parameter i
of function template f
is of type
short
, while the non-type template parameter i
of class template
B
is of type int
, and this situation is explicitly forbidden by
the standard (at the time of writing this is specified in [temp.deduct.type] p. 19). However, the default template argument for the non-type
template parameter i
of function template f
is exactly the
required value (0
, as in the type of pf
), so this program should now be correct. However, as I
said before, I do not think this is the example the authors of this
defect report had in mind.
Why do contexts where deduction fails have to be mentioned explicitly in the standard?
Thank you for your help!
解决方案
推荐阅读
- php - 如何使用 php 代码在 GCE 上创建凭证(用于谷歌表格)?
- mysql - 将 SQL 查询结果卸载到变量而不是 shell 脚本上的文件
- javascript - 仅当使用 knex 唯一时才插入
- python - 显示警报时从窗口警报中删除警报文本
- r - 将 2 个数据框与重复列合并?
- c# - 我正在制作一个相册查看器,但 MULTISELECT 只得到一张照片。怎么做?
- c# - 保存并加载我的 listview/observablecolletion 到 txt
- c# - 使用带有列表的 Windows API EnumThreadWindows 的内存泄漏
- json - 如何在 Django 中验证之前从请求中的子对象获取信息?
- java - AuthorizedFeignClient 具有自定义角色的 JHipster 微服务与 UAA