gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:58:52 25 4
gpt4 key购买 nike

这里我想锁步迭代两个 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 开发版本中起作用。

关于foreach - 即使给出了类型,dmd 也无法推断类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22386412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com