- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
为什么这是模棱两可的?
template<class T> void g(T) {} // 1
template<class T> void g(T&) {} // 2
int main() {
int q;
g(q);
}
我知道这是部分排序上下文。我的想法可能是错误的:#2 中的任何 T& 都可以放在#1 中,但#1 中的任何 T 都不能放在#2 中。所以部分排序应该有效。
最佳答案
好的。我认为这就是您要找的。没有深入研究参数与参数类型比较的两次应用,标准中的以下内容让我大吃一惊:
C++11 §14.8.2.4p5
Before the partial ordering is done, certain transformations are performed on the types used for partial ordering:
- If P is a reference type, P is replaced by the type referred to.
- If A is a reference type, A is replaced by the type referred to.
C++11 §14.8.2.4p6 继续讨论当两者 都是引用类型时会发生什么,但这在这里不适用(尽管也是一个有趣的读物)。在你的情况下,只有一个,所以它被剥离了。从那里:
C++11 §14.8.2.4p7
Remove any top-level cv-qualifiers:
- If P is a cv-qualified type, P is replaced by the cv-unqualified version of P.
- If A is a cv-qualified type, A is replaced by the cv-unqualified version of A.
现在两者完全相等,因此你有歧义,我相信这是从 C++11 §14.8.2.4p10 巩固的。 C++11 §14.8.2.4p9 的文本涵盖了这两种引用类型,而这里又不是这种情况:
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. Otherwise, neither template is more specialized than the other.
但阅读本节中的标准对我来说就像破译希腊语,所以我可能方式偏离了基础。 (对希腊人没有冒犯 =P)。
然而,它确实让我想到了“const T&
与 T
,给定相同的调用条件 g(q)
,如果我刚刚阅读的所有内容都按书面执行,那么也应该是模棱两可的。”果然,我试了一下,同样的歧义被标记出来了。
关于c++ - 使用 L-value-ref 进行部分排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14453829/
话说,尾部的++在这里没有实际作用? 最佳答案 l+l++ 未定义。您的表达式中没有序列点来分隔对 l 的访问和后增量。它可以做任何事情,包括具有与 l+l 相同的效果。 编辑:问题和答案在 Why
我正在研究成员资格算法,我正在研究这个特定问题,该问题说明如下: 展示一种算法,给定任何常规语言 L,确定 L 是否 = L* 所以,我的第一个想法是,我们有 L*,它是 L 的 Kleene 星并确
我试图弄清楚如何使用 Javascript 生成一个随机 11 个字符串,该字符串需要特定的字母/数字序列,以及位置。 ----------------------------------------
我一直在 LinqPad 中试验查询。我们有一个表 Lot,其中有一列 Side char(1)。当我编写 linq to sql 查询 Lots.Where(l => l.Side == 'A')
这个问题在这里已经有了答案: Iterate over all pairs of consecutive items in a list [duplicate] (7 个答案) 关闭 7 年前。 假
列表 ['a','a #2','a(Old)'] 应变为 {'a'} 因为 '# ' 和 '(Old)' 将被删除,并且不需要重复项列表。我努力用生成器开发列表理解,并决定这样做,因为我知道它会起作用
我正在为蛇和梯子制作一 block 板,到目前为止,我已经按降序打印了板。但是,我需要以正确的方式打印电路板。 编辑“螺旋下降”意味着 100...91 81...90 80...71 ...
字符串“Hello\n”等于 {'H','e','l','l','o','\','n','\0'} 或 {'H','e','l','l','o','\n','\0'}? 是否在字符串定义中添加转义序列
这个问题在这里已经有了答案: Different behaviour for list.__iadd__ and list.__add__ (3 个答案) 关闭 8 年前。 ls = [1,2,3]
当我在编写一个程序时,我在我的代码中看到了一个奇怪的行为。这是我所看到的。 >>> l = [1,2,3,4,5,6,7,8] >>> g = [] >>> for i in l: ... g
我明白了what a Y Combinator is , 但我不明白这个来自 Wikipedia page 的“新颖”组合子的例子: Yk = (L L L L L L L L L L L L L
Exception ParseException is not compatible with throws clause in Comparator.compare(L, L). 我在java 6上
期望的输出 我想要一个函数返回一个列表,这样,给定一个“困惑的”列表 l,每个元素都是 l 对应元素的索引,如果 l 已排序。 (抱歉,我想不出更简单的说法。) 示例 f([3,1,2]) = [2,
你好,我正在查看“假设一个排序数组在你事先不知道的某个枢轴旋转。(即 0 1 2 4 5 6 7 可能变成 4 5 6 7 0 1 2)”这个问题的 C++ 解决方案。你如何有效地在旋转数组中找到一个
让我们考虑这个简单的例子: import numpy as np a=np.arange(90) a=a.reshape(6,3,5) 我想得到一个数组 b形状 (6*5,3+1=4) 与 b[0:6
我正在编写一个 q 脚本,它在特定路径中加载一个数据库并对其进行一些处理。 db 的位置目前在脚本中是硬编码的,但我想将 db 路径作为参数传递并让它从变量中的路径加载。 目前它看起来像这样: q)
为什么我收到错误 Device: (3:9741) (0,l.useLinkBuilder) is not a function。 (在 '(0,l.useLinkBuilder)()' 中,'(0,
我有 ADT 版本 23.0.4 并安装了 Android 5.0 的 SDK 平台。 我读到 Android 5.0 Lolipop 的 API 级别为 21。但是在 Eclipse 的“新建应用程
我在 Google Play Store 中实现了一个抽屉导航,我想在 DrawerLayout 中设置列 TableView 的选定项目。但是后来发现在touch模式下无法选中item,有一个i
作为 C++ 的新手,我基本上有一个关于 g++ 编译器的问题,尤其是库的包含。考虑以下生成文件: CPPFLAGS= -I libraries/boost_1_43_0-bin/include/ -
我是一名优秀的程序员,十分优秀!