output ranges: by ref or by value?

Steven Schveighoffer schveiguy at yahoo.com
Sat Jan 2 04:12:27 PST 2010


On Fri, 01 Jan 2010 18:45:35 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Rainer Deyke wrote:
>> Andrei Alexandrescu wrote:
>>> If the implementor of consume() forgets to call save(), the situation  
>>> is
>>> unpleasant albeit not catastrophic: for most struct ranges things will
>>> continue to work, but for class ranges the function will fail to  
>>> perform
>>> to spec. I don't know how to improve on that.
>>  Require that all ranges are structs.  If you want to implement a range
>> as a class, use a wrapper struct that creates a new object in its
>> postblit function.  The wrapper struct can be made generic and placed in
>> the standard library.
>>  Same performance as the current approach, slightly more effort on the
>> part of the range implementor, much easier and less error-prone on the
>> side of the range user.
>
> Oh, besides it doesn't work for struct ranges that iterate one-pass  
> streams.

What does save do in those cases?

-Steve



More information about the Digitalmars-d mailing list