On Monday, 24 July 2017 at 14:30:01 UTC, Atila Neves wrote:
struct Foo { }struct S { Foo* _foo; bool _isShared;this(this T, U)(U foo) if(is(T == shared) && is(U == shared(Foo)*) || !is(T == shared) && is(U == Foo*)) {static if(is(T == shared)) _isShared = true; _foo = foo; } ~this() { import std.stdio: writeln;_isShared ? writeln("shared dtor") : writeln("non-shared dtor");} } void main() { auto f = Foo(); auto sf = shared Foo(); auto s = S(&f); auto ss = shared S(&sf); }
Exactly this. You must design struct to support shared type, in which case it's better and more straightforward to just write shared destructor rather than work it around. Same for immutable.
