fork download
  1. import std.stdio;
  2.  
  3. struct Foo
  4. {
  5. int[] a;
  6. int b;
  7. this(this)
  8. {
  9. writeln("blit copy is done now let's post-blit'");
  10. // a memory is the same as the source
  11. a = a.dup;
  12. // a memory is now only for this instance
  13. }
  14. }
  15.  
  16. void main()
  17. {
  18. Foo foo1 = Foo([1,2], 3);
  19. writeln("blit copy will happen");
  20. Foo foo2 = foo1;
  21. // would be true without the "postblit"
  22. assert(foo1.a.ptr != foo2.a.ptr);
  23. }
Success #stdin #stdout 0s 16416KB
stdin
Standard input is empty
stdout
blit copy will happen
blit copy is done now let's post-blit'