Ranges and/versus iterators

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 25 09:28:57 PDT 2010


On 03/25/2010 05:32 AM, Fawzi Mohamed wrote:
> thinking more about this, you are right something that returns a ref can
> be used exactly the same way as something that returns a value if one
> takes the value with
> auto val=returnRefOrVal;
> can be used as value exactly in the same way.
> Whereas something that returns a T or a T* , need an explicit conversion.
> That is easy to do, and one can even easily wrap the delegate in place
> with something that returns T instead of T*, but the conversion has to
> be explicit (before feeding it to the code), or explicitly tested for in
> the code.
> In practice I hadn't real problems due to this, but it is something that
> is uglier than ref return.
> On the other hand it is easier to know if you might modify the value
> that you received expecting to modify the underlying structure.

I see. So what you're saying is that maybe the entire idea of iterating 
streams and arrays in a unified way may be problematic, because you can 
do different things with the elements of the two. While I partially 
agree with that, there are a lot of things that one can do the same way 
over a stream or a collection, and I wasn't able to find a way to do 
that that's reasonably efficient for both.

Andrei




More information about the Digitalmars-d mailing list