繁体   English   中英

即使给出了类型,dmd也无法推断出类型

[英]dmd can't infer type even when type is given

在这里,我想锁定两个size_t数组的锁步迭代

import std.stdio;
import std.range;
import std.exception;
import std.conv;

struct zip(R,Q)
if(isInputRange!(R) && isInputRange!(Q))
{
    R r;
    Q q;
    @property
    const auto front() {
        return tuple(r.front, q.front);
    }
    void popFront() {
        r.popFront();
        q.popFront();
    }
    @property
    const bool empty() {
        bool re = r.empty;
        enforce(re == q.empty);
        return re;
    }
}

void main() {
    size_t[] a = [0,1,2,3,4,5];
    size_t[] b = [2,3,4,5,6,7];
    foreach(size_t i, size_t j; zip!(size_t[],size_t[])(a,b)) {
        writeln(to!string(i) ~ " " ~ to!string(j));
    }
}

但这无法编译

src/Interpreter.d(30): Error: cannot infer argument types

但是,当我更改foreach行使用uint而不是size_t时(我在32位笔记本电脑上)

foreach(uint i, uint j; zip!(size_t[],size_t[])(a,b)) {

它编译并运行得很好。 这是怎么回事?

这可能是一个错误。 在v2.065.0中它不起作用,但它确实在最新的git-head开发版本中有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM