dmd 2.029 release
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Apr 23 06:24:59 PDT 2009
Steven Schveighoffer wrote:
> On Thu, 23 Apr 2009 09:06:38 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> 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?
Red herring. If streamOut is a member, no need for T.
> 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.
It must be a sink _object_ so it can hold its own state. And it must
support put() so it integrates with statically-bound output ranges.
interface OutRange
{
void put(... a number of overloads ...);
}
> And I wholeheartedly agree that we need this. I've run into many
> situations where toString makes no sense.
Same here...
Andrei
More information about the Digitalmars-d-announce
mailing list