如何在dlang中传递file.ByChunk?

如何在dlang中传递file.ByChunk?,d,dmd,D,Dmd,我是D区的新手 我有以下代码: auto file = File("test.txt", "r"); scope(exit) file.close(); foreach (letter; getTextKernel(file.byChunk(8192))) { writeln(letter); } 我的getTextKernel看起来像: string[] getTextKernel(InputRange!ubyte[] text) pure { ... } 我收到错误消息: 无法

我是D区的新手

我有以下代码:

auto file = File("test.txt", "r");
scope(exit) file.close();

foreach (letter; getTextKernel(file.byChunk(8192))) {
    writeln(letter);
}
我的getTextKernel看起来像:

string[] getTextKernel(InputRange!ubyte[] text) pure { ... }
我收到错误消息: 无法使用参数类型(ByChunk)调用getTextKernel(InputRange!ubyte[]text)

关于byChunk的文档:
返回设置为一次从文件句柄读取一个块的输入范围。

更新:整个计划

import std.stdio;

string[] getTextKernel(R)(R text) pure {
    return ["aa", "bbb", "ccc"];
}

void main() {
    writeln("Hello master dmitry!");

    auto file = File("test.txt", "r");
    scope(exit) file.close();

    // StubdGenetics genetic;
    foreach (letter; getTextKernel(file.byChunk(8192))) {
        writeln(letter);
    }
}

错误:纯函数“app.getTextKernel!”!(ByChunk).getTextKernel'不能调用不纯析构函数'std.stdio.File.ByChunk.~这'

通常的方法是使
getTextKernel
接受模板参数

string[] getTextKernel(R)(R text) pure   { ... }

因为范围在D中是惰性的,所以它们通常是定制的、一次性的类型<代码>输入范围在我的经验中几乎从未使用过。使用它是有原因的,但它比较慢(使用运行时调度而不是编译时),而且通常不需要。

注意,您可能需要使用
isInputRange来约束
R
!R
是(ElementType!R:ubyte[])
(两者都由)Thx提供,但现在我在使用
修饰符时遇到了问题。查看我的更新bychunk的东西不是纯粹的。。除了不使用纯的或通过chunck本身而不是范围之外,你对此无能为力