简体   繁体   English

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

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

Here I want to lockstep iterate over two arrays of size_t 在这里,我想锁定两个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));
    }
}

But this fails to compile with 但这无法编译

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

However when I change the foreach line to use uint instead of size_t (I'm on a 32-bit laptop) 但是,当我更改foreach行使用uint而不是size_t时(我在32位笔记本电脑上)

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

It compiles and runs just fine. 它编译并运行得很好。 What's going on? 这是怎么回事?

It might be a bug. 这可能是一个错误。 In v2.065.0 it doesn't work, but it does work in the latest git-head development version. 在v2.065.0中它不起作用,但它确实在最新的git-head开发版本中有效。

暂无
暂无

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

相关问题 即使枚举类型被密封,foreach也不会进行类型检查 - foreach won't type check even when enumerated type is sealed 为什么编译器不能为自定义集合推断循环变量类型? - Why compiler can not infer loop variable type for custom collections? DMD不强制限制foreach - DMD doesn't force restrictions on foreach 无法推断复杂的闭包返回类型 SwiftUI ForEach - Unable to infer complex closure return type SwiftUI ForEach foreach() 参数必须是数组|对象类型,使用 cookies 时在 Laraval 8 中给出的字符串 - foreach() argument must be of type array|object, string given in Laraval 8 when using cookies 遍历 object 会抛出“元素隐含地具有‘任何’类型,因为‘字符串’类型的表达式不能用于索引类型’ - Iterating through object throws 'Element implicitly has an 'any' type because expression of type 'string' can't be used to index type' 在 C# 中,为什么我不能在 foreach 循环中修改值类型实例的成员? - In C#, why can't I modify the member of a value type instance in a foreach loop? PantaRei.Classes.Enums.ProductTypeA1Enum.Types'是'type',在给定的上下文中无效 - PantaRei.Classes.Enums.ProductTypeA1Enum.Types' is a 'type', which is not valid in the given context Laravel 7 动态“添加字段”表单。 foreach() 参数必须是数组|对象类型,null - Laravel 7 dynamic "add fields" form. foreach() argument must be of type array|object, null given 我可以在int中输入一个long类型的1d数组元素吗? - Can i type cast a long type 1d array element into int?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM