我得到這個錯誤:當我從同一個函數中返回不同類型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