c++ - 什么时候一个模板比另一个模板更专业? 'And'/'Or' 与逻辑混淆。

标签 c++ c++11 partial-ordering

在C++11草案的14.8.2.4p10中,有写

If for each type being considered a given template is at least as specialized for all types and more specialized for some set of types and the other template is not more specialized for any types or is not at least as specialized for any types, then the given template is more specialized than the other template.

为什么会有“或至少不专门用于任何类型”?据我所知,如果我们有一个类型列表

T1, T2, T3
U1, U2, U3

如果所有 T 至少都一样特化,而有些则更特化。并且没有一个 U 更特化,那么在我看来,从逻辑上讲,T 的集合作为一个整体比 U 的集合更特化。当我们没有一个至少比相应的 Ts 特化时,为什么还有提到的后备?

最佳答案

更新:现在已添加为 official C++ Issue


我终于弄清楚了如何阅读有问题的段落。下面我已经标出它了

If for each type being considered a given template is at least as specialized for all types, and

  • more specialized for some set of types and the other template is not more specialized for any types, or
  • {the other template} is not at least as specialized for any types,

then the given template is more specialized than the other template.

这样下面的第一个模板也比第二个模板更专业

template<typename T> void f(T*);
template<typename T> void f(T);

请注意,第一个模板的参数至少与第二个模板一样特化,但并未定义为“更特化” - 该术语仅适用于两个参数都是引用且适用某些条件的情况(参见第 9 段14.8.2.4) 。这些规则显然要遵循任何正式的订购法。第二个模板至少不像第一个模板那样专门化。这意味着第二个项目符号适用,而不是第一个项目符号。

关于c++ - 什么时候一个模板比另一个模板更专业? 'And'/'Or' 与逻辑混淆。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15702143/

相关文章:

C++模板解释

algorithm - 对部分排序列表进行排序的最佳方法是什么?

c++ - ActiveQt Com 应用程序示例 - COM 服务器未在 Windows 注册表中注册 (Qt4.7.4)

c++ - 比较日期的安全方法 (time_t)

c++ - MacPorts Clang 3.1 缺少标准库安装?

c++ - 将 std::unique_ptr 类成员标记为 const

c++ - 解决简单哈希表中的内存泄漏和语法问题

c++ - 要引用的默认值,c++

c++ - 我可以确保 RVO 用于重新解释的值吗?

c++ - 如何确定作业的两个副作用是否未排序?