ubyte[] -> immutable(ubyte)[]
Andrej Mitrovic
andrej.mitrovich at test.com
Fri Sep 3 14:10:44 PDT 2010
This is from TDPL page 407:
import std.algorithm,
std.concurrency,
std.stdio;
void main()
{
enum bufferSize = 1024 * 100;
auto tid = spawn(&fileWriter);
// Read loop
foreach (immutable(ubyte)[] buffer; stdin.byChunk(bufferSize))
{
send(tid, buffer);
}
}
void fileWriter()
{
// write loop
while (true)
{
auto buffer = receiveOnly!(immutable(ubyte)[])();
tgt.write(buffer);
}
}
Error:
C:\DMD\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(1943):
Error: cannot implicitly convert expression (buffer) of type ubyte[]
to immutable(ubyte)[]
Yet interestingly I can't use type inference:
foreach (buffer; stdin.byChunk(bufferSize))
{
send(tid, buffer);
}
Error: stdin_stdout_copy.d(11): Error: cannot infer type for buffer
But in the original code I get back a mutable ubyte[] which I can't implicitly convert to immutable (I'd need a copy first). There's no .dup or .idup property for stdin.byChunk. So what am I supossed to do here?
More information about the Digitalmars-d-learn
mailing list