foreach, an analogy

Walter Bright newshound at digitalmars.com
Thu Oct 19 09:06:08 PDT 2006


Gregor Richards wrote:
> Walter Bright wrote:
>> The C++ iterator approach has a serious problem: collections need to 
>> be linearized. This is not reasonable for some types of collections, 
>> such as a binary tree, which really wants to be traversed in a 
>> recursive descent fashion, rather than linearly.
> 
> A slight modification can fix that:
> 
>  for (auto bar = foo.begin(); !(bar is null); bar = bar.next())
> 
> Anyway, my point was merely that 'foreach' is not analogous to the 
> too-small-door, since it's merely an alternative to 'for' :)

How do you make for work with the following data structure:

	struct Tree
	{	Tree* left;
		Tree* right;
		int data;
	}
?



More information about the Digitalmars-d-announce mailing list