Advertisement
Guest User

Untitled

a guest
Feb 17th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.52 KB | None | 0 0
  1. module main;
  2.  
  3. import std.stdio;
  4.  
  5. Foo[uint] foo;
  6.  
  7. void main()
  8. {
  9.     add( new Foo(1) );
  10.     add( new Foo(2) );
  11.     add( new Foo(3) );
  12.     add( new Foo(4) );
  13.    
  14.     writeln("length: ", foo.length);
  15.    
  16.     foreach_reverse(key, f; foo)
  17.     {
  18.         if(key >= 2 && key <= 3)
  19.         {
  20.             remove(f);
  21.             continue;
  22.         }
  23.         writeln("k: ", key);
  24.     }
  25.    
  26.     writeln("length: ", foo.length);
  27. }
  28.  
  29. void add(Foo f)
  30. {
  31.     foo[f.id] = f;
  32. }
  33.  
  34. void remove(Foo f)
  35. {
  36.     foo.remove(f.id);
  37. }
  38.  
  39. class Foo
  40. {
  41.     uint id;
  42.    
  43.     this(uint id)
  44.     {
  45.         this.id = id;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement