On Saturday, 12 August 2017 at 19:34:35 UTC, Arek wrote:
On Friday, 21 July 2017 at 08:53:44 UTC, Atila Neves wrote:


This works fine in dmd 2.075:

struct A
{
    this(string a) {}
    this(string a) shared {}

    ~this() {}

this(this T)(this) {} // you can reflect to find out if shared
}

void main()
{
    auto nonShared = A("");
    auto shared_ = shared A("");
    auto nonSharedCopy = nonShared;
    auto sharedCopy = shared_;
}


Atila

This look interesting: this(this T)(this) {}
What is it? Postblit?

It compiles but doesn't work for me.

this(this T)(this) {writeln("postblit"); } // doesn't print anything

Arek

It's a template postblit constructor - it'd get instantiated differently depending on the type of the implicit `this` parameter and would be able to fix things up taking into account whether or not `this` was shared (or immutable).

Atila

Reply via email to