我得到这个错误:当我从同一个函数中返回不同类型InputRanges的Error: mismatched function return type inference of
。由take
或takeExactly
返回的类型由于某种原因与原始输入范围兼容,但与我的自定义输入范围不兼容。函数的返回类型不匹配的现象范围
auto decode(Range)(Range r) {
if (r.front == 0) {
r.popFront();
return r;
} else if (r.front == 1) {
r.popFront();
return r.take(3); // this is compatible with the return type above
} else if (r.front == 2) {
r.popFront();
return MyRange(r); // this is not compatible with the types above
}
}
发生了什么事?
'MyRange'是否有切片('opSlice')? – sigod
是的,它有切片。 – Tamas
实际上这就是答案:如果范围支持切片,则r和r.take(3)具有相同类型,并且它与MyRange(r)不同。谢谢!! – Tamas