On Sunday, 8 February 2015 at 13:13:18 UTC, Marc Schütz wrote:
On Sunday, 8 February 2015 at 01:57:55 UTC, Meta wrote:
On Sunday, 8 February 2015 at 00:31:42 UTC, Mike wrote:
Is `this` overloaded to mean "this class" in a static context or is `this` only valid in a non-static context. Please clarify, and if it's a bug, help me understand so I can make an accurate and actionable bug report.

`this` should only be valid in a non-static context, as far as I know. That's pretty much what static means: "there is no `this`".

The following is a useful idiom for static factory methods:

    struct S {
        this(int x) {
        }

        static auto make(int x) {
            return typeof(this)(x);
        }
    }

Okay, I forgot about that one. `typeof` is somewhat of a special case, though, since you can also do typeof(1/0) and get `int`.

Reply via email to