Repost: make foreach(i, a; range) "just work"

Regan Heath regan at netmail.co.nz
Thu Feb 20 08:07:32 PST 2014


On Thu, 20 Feb 2014 13:04:55 -0000, w0rp <devw0rp at gmail.com> wrote:

> I don't think this is a good idea.

Which part?  The initial solution to my initial problem, or one of the 3  
schemes mentioned?

> Say you have a class with range methods and add opApply later. Only the  
> opApply delegate receives a type other than size_t for the first  
> argument. Now the foreach line infers a differnt type for i and code in  
> the outside world will break.

Only if the compiler prefers opApply to range methods, does it?

And, if it prefers range methods then any existing class with opApply  
(with more than 1 variable) that gets range methods will break also,  
because foreach(<more than 1 variable>; range) does not (currently) work.

> More importantly, this gets in the way of behaviour which may be  
> desirable later, foreach being able to unpack tuples from ranges.

<snip> :)

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list