output ranges: by ref or by value?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jan 1 14:54:12 PST 2010


Michel Fortin wrote:
> On 2010-01-01 15:53:42 -0500, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> save() is not only for classes. It also distinguishes input ranges 
>> from forward ranges. It's the primitive that STL didn't define but 
>> should have.
> 
> Right. I still maintain that it's a bad approach. I've written a lot of 
> algorithms in C++ that worked with iterators, always assuming assignment 
> would copy the state. Fortunately I didn't had to use input iterators 
> with them, most of the time. But I did once or twice, and the thing was 
> working slightly off.
> 
> What I'd do instead is somehow make input ranges non-copyable. They 
> could be either passed by ref or moved, never copied. This way they 
> would still behave exactly like array slices, only not copyable, and you 
> get a compile-time error if you try to copy them which is infinitely 
> better than a subtle change in behavior.

I tried that, it makes input ranges next to unusable. save() is an 
imperfect but workable solution.

Andrei



More information about the Digitalmars-d mailing list