DMD 0.170 release

Walter Bright newshound at digitalmars.com
Tue Oct 17 11:54:01 PDT 2006


BCS wrote:
> Ary Manzana wrote:
> 
> 
> 
>  class Tree {
> 
>      int inorder(int delegate(inout int)) {
>              // inorder traversal
>      }
> 
>      int preorder(int delegate(inout int)) {
>              // preorder traversal
>      }
> 
>     int postorder(int delegate(inout int)) {
>              // postorder traversal
>      }
> 
>  }
> 
>  void main() {
>      Tree t = giveMeSomeTree();
> 
>      foreach(int i : &t.inorder) {
>          // something
>          }
> 
>      foreach(int i : &t.preorder) {
>          // something
>          }
> 
>      foreach(int i : &t.postorder) {
>          // something
>          }
> 
>  }
> 
> If I understand correctly, the above works with what is there now.

You are correct, with delegates now allowed as the 'aggregate', you can 
have any order traversal needed for the particular collection type. 
(Nit: replace the ':' in your examples with ';'.)

> The things with the foreach_reverse is (I think) mostly for actuals 
> arrays, and the opApplyReverse is really there more for orthogonality 
> than need. that orthogonality has some cool side effects* so I'd say 
> leave them in.

Right. a.reverse reverses an array in place, and trying to support:
	int[] a;
	foreach (v; &a.reverse)
is an awful hack.



More information about the Digitalmars-d-announce mailing list