Advertisement
WeltEnSTurm

Untitled

Apr 15th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.35 KB | None | 0 0
  1.  
  2.  
  3. struct Aware(T) {
  4.     bool changed;
  5.     alias data this;
  6.  
  7.  
  8.     @property
  9.     ref T data() {
  10.         return d;
  11.     }
  12.  
  13.     @property
  14.     void data(T assgn) {
  15.         if(d != assgn) {
  16.             d = assgn;
  17.             changed = true;
  18.         }
  19.     }
  20. private:
  21.     T d;
  22. }
  23.  
  24. class Test(T) {
  25.     T x;
  26. }
  27.  
  28. unittest {
  29.     Aware!(Test!int) test;
  30.     test = new Test!int;
  31.     test.x = 5;
  32.     assert(test.x == 5);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement