1 module foreignptr;
2 
3 abstract
4 class ForeignPtr(T) {
5 	T __foreignPtr;
6 	alias __foreignPtr this;
7 }
8 
9 private
10 class CTForeignPtr(alias deconstruct, T) : ForeignPtr!T {
11 	this(T ptr) {
12 		this.__foreignPtr = ptr;
13 	}
14 	~this() {
15 		deconstruct(__foreignPtr);
16 	}
17 }
18 private
19 class RTDForeignPtr(T) : ForeignPtr!T {
20 	 void delegate(T) __deconstruct;
21 	this(T ptr, void delegate(T) deconstruct) {
22 		this.__foreignPtr = ptr;
23 		this.__deconstruct = __deconstruct;
24 	}
25 	~this() {
26 		this.__deconstruct(__foreignPtr);
27 	}
28 }
29 class RTFForeignPtr(T) : ForeignPtr!T {
30 	 void function(T) __deconstruct;
31 	this(T ptr, void function(T) deconstruct) {
32 		this.__foreignPtr = ptr;
33 		this.__deconstruct = __deconstruct;
34 	}
35 	~this() {
36 		this.__deconstruct(__foreignPtr);
37 	}
38 }
39 
40 ForeignPtr!T foreignPtr(alias deconstruct, T)(T ptr) {
41 	return new CTForeignPtr!(deconstruct, T)(ptr);
42 }
43 
44 ForeignPtr!T foreignPtr(T)(void delegate(T) deconstruct, T ptr) {
45 	return new RTDForeignPtr!T(ptr, deconstruct);
46 } 
47 ForeignPtr!T foreignPtr(T)(void function(T) deconstruct, T ptr) {
48 	return new RTFForeignPtr!T(ptr, deconstruct);
49 } 
50 ////ForeignPtr!T foreignPtr(T)(T ptr, void delegate(T) deconstruct) {
51 ////	return new RTForeignPtr!T(ptr, deconstruct);
52 ////} 
53 ////ForeignPtr!T
54 ////delegate(void delegate(T))
55 ////foreignPtr(T)(T ptr) {
56 ////	return deconstruct => new RTForeignPtr!T(ptr, deconstruct);
57 ////} 
58 ////ForeignPtr!T
59 ////delegate(T)
60 ////foreignPtr(T)(void delegate(T) deconstruct) {
61 ////	return ptr => new NewForeignPtr(ptr, deconstruct);
62 ////} 
63