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

Regan Heath regan at netmail.co.nz
Fri Feb 21 03:21:39 PST 2014


On Thu, 20 Feb 2014 17:09:31 -0000, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Thu, 20 Feb 2014 11:07:32 -0500, Regan Heath <regan at netmail.co.nz>  
> wrote:
>
>> Only if the compiler prefers opApply to range methods, does it?
>
> It should. If it doesn't, that is a bug.
>
> The sole purpose of opApply is to interact with foreach. If it is masked  
> out, then there is no point for having opApply.

Thanks.

So, if we had this support which I am asking for:

	foreach(index, value; range) { }

And, if someone adds opApply to that range, with a different type for the  
first variable then an existing foreach (using index, value) is likely to  
stop compiling due to type problems.

This seems acceptable to me.

There is an outside chance it might keep on compiling, like if 'i' is not  
used in a strongly typed way, i.e. passed to a writefln or similar.  In  
this case we have silently changed behaviour.

Is this acceptable?

R

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


More information about the Digitalmars-d mailing list