Guest User

Untitled

a guest
Jun 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. module sealed;
  2. import std.stdio;
  3.  
  4. @trusted struct Sealed(T)
  5. {
  6. //private T* p;
  7. public T* p;
  8.  
  9. this(ref T t)
  10. {
  11. this.p = &t;
  12. writefln("Sealed.this : &t = %08X, p == %08X", &t, cast(uint)p);
  13. }
  14.  
  15. auto opDispatch(string s, T...)(auto ref T args)
  16. {
  17. mixin("return (*p)." ~ s ~ "(args);");
  18. }
  19. auto opDispatch(string s, T...)(auto ref T args) const
  20. {
  21. mixin("return (*p)." ~ s ~ "(args);");
  22. }
  23. auto opDispatch(string s, T...)(auto ref T args) shared
  24. {
  25. mixin("return (*p)." ~ s ~ "(args);");
  26. }
  27. auto opDispatch(string s, T...)(auto ref T args) shared const
  28. {
  29. mixin("return (*p)." ~ s ~ "(args);");
  30. }
  31. auto opDispatch(string s, T...)(auto ref T args) immutable
  32. {
  33. mixin("return (*p)." ~ s ~ "(args);");
  34. }
  35.  
  36.  
  37. @disable ~this()
  38. {
  39. }
  40. }
  41.  
  42. import std.algorithm;
  43. void swap(T)(ref Sealed!T a, ref Sealed!T b)
  44. {
  45. writefln("sealed.swap, a.p = %08X, b.p = %08X", a.p, b.p);
  46. std.algorithm.swap(*a.p, *b.p);
  47. }
Add Comment
Please, Sign In to add comment