Guest User

Untitled

a guest
Oct 4th, 2018
177
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Unique(T, Allocator = Mallocator) {
  2.     private alias Alloc = TypedAllocator!Allocator;
  3.     mixin SmartPtrMembers!T;
  4.  
  5.     @disable this();
  6.     @disable this(this);
  7.     @disable void opAssign();
  8.  
  9.     private void makeElement(Args...)(Args args) {
  10.         mElement = Alloc.allocate!T();
  11.         construct(mElement, args);
  12.     }
  13.  
  14.     private this(EmptyInitializer) {
  15.         makeElement();
  16.     }
  17.  
  18.     private this(Args...)(auto ref Args args) if (Args.length > 0) {
  19.         makeElement(args);
  20.     }
  21.  
  22.     ~this() {
  23.         destroyElement();
  24.     }
  25.  
  26.     static typeof(this) make(Args...)(Args args) {
  27.         static if (Args.length > 0) {
  28.             return typeof(this)(args);
  29.         } else {
  30.             return typeof(this)(empty);
  31.         }
  32.     }
  33. }
RAW Paste Data