On Thu, 23 Apr 2009 09:06:38 -0400, Andrei Alexandrescu <[email protected]> wrote:

It ought to be at least as simple as:
 struct Foo(A, B, C){
A[10] a;
B b;
C c;
void toString(Sink sink){
   foreach(x; a) sink(x);
   sink(b);
   sink(c);
}
}
... but it's not, you have to create a silly buffer to put all your strings in, even if there are 200 million of them and your giant string is just going to be written to a file anyway.

Yes. The way it should be is not with sink, but with the standard output iterator method put().

void streamOut(T, R)(T object, R range)
{
     foreach(x; a) range.put(x);
     range.put(b);
     range.put(c);
}

What is the T object for?

This has to go into object.d and be part of the runtime, where std.range doesn't exist. There is nothing stopping you from calling:

streamOut(&outputrange.put);

So I'd rather have a sink function.

And I wholeheartedly agree that we need this. I've run into many situations where toString makes no sense.

-Steve

Reply via email to