scopeがなくなるらしいので
色々お話しましたがもう自分用にこれでいいやと思った.
import std.stdio; struct AutoDeleted(T) { private T t; public this(Args...)(Args args) { t = new T(args); } public ~this() { delete t; t = null; } private @disable this(this){} public alias t this; } class A { int v; this(int i) { v = i; } ~this() { writeln("dest"); } int get() { return v; } } void f(A a) { writeln(a.get()); } void main() { { auto a = AutoDeleted!A(1); f(a); writeln("inner scope"); } writeln("outer scope"); // copy is disabled. //auto b = a; }
1 inner scope dest outer scope
class Aを引数なしのコンストラクタで作れませんね.