【发布时间】:2017-06-02 17:22:00
【问题描述】:
我是 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 { ... }
我收到错误: getTextKernel (InputRange!ubyte[] text) 不能使用参数类型 (ByChunk) 调用
关于 byChunk 的文档:Returns an input range set up to read from the file handle a chunk at a time.
更新:整个计划
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.~this'
【问题讨论】: