[Issue 17713] New: Template 'this' parameters for static methods

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 3 06:37:58 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17713

          Issue ID: 17713
           Summary: Template 'this' parameters for static methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timon.gehr at gmx.ch

Template 'this' parameters should work even when the method is static.

For example:

mixin template Constructors(){
    this(){ }
    this()immutable{ }
    this()shared{ }
}

class A {
public:
    static C getInstance(this C)() {
        return new C();
    }
private:
    mixin Constructors;
}
class B : A {
private:
    mixin Constructors;
}

void main(){
    auto a = A.getInstance();
    auto b = B.getInstance();
    static assert(is(typeof(a)==A));
    static assert(is(typeof(b)==B));
    auto ai = (immutable(A)).getInstance();
    auto bs = (shared(B)).getInstance();
    static assert(is(typeof(ai)==immutable(A)));
    static assert(is(typeof(bs)==shared(B)));
}

Also see: http://forum.dlang.org/post/olv6se$1ohc$1@digitalmars.com

--


More information about the Digitalmars-d-bugs mailing list