| 1 |
mixin template Constructors(){ |
| 2 |
this(){ } |
| 3 |
this()immutable{ } |
| 4 |
this()shared{ } |
| 5 |
} |
| 6 |
|
| 7 |
class A { |
| 8 |
public: |
| 9 |
static T getInstance(this T)() { |
| 10 |
return new T(); |
| 11 |
} |
| 12 |
private: |
| 13 |
mixin Constructors; |
| 14 |
} |
| 15 |
|
| 16 |
class B : A { |
| 17 |
private: |
| 18 |
mixin Constructors; |
| 19 |
} |
| 20 |
|
| 21 |
void f(){ |
| 22 |
auto a = (new A).getInstance; |
| 23 |
auto b = (new B).getInstance; |
| 24 |
static assert(is(typeof(a) == A)); |
| 25 |
static assert(is(typeof(b) == B)); |
| 26 |
|
| 27 |
auto ca = (new immutable A).getInstance; |
| 28 |
auto sb = (new shared B).getInstance; |
| 29 |
static assert(is(typeof(ca) == immutable A)); |
| 30 |
static assert(is(typeof(sb) == shared B)); |
| 31 |
} |
| 32 |
|
| 33 |
// https://issues.dlang.org/show_bug.cgi?id=10488 |
| 34 |
version(none) |
| 35 |
void g(){ |
| 36 |
auto a = A.getInstance(); |
| 37 |
auto b = B.getInstance(); |
| 38 |
static assert(is(typeof(a)==A)); |
| 39 |
static assert(is(typeof(b)==B)); |
| 40 |
|
| 41 |
auto ai = (immutable(A)).getInstance(); |
| 42 |
auto bs = (shared(B)).getInstance(); |
| 43 |
static assert(is(typeof(ai)==immutable(A))); |
| 44 |
static assert(is(typeof(bs)==shared(B))); |
| 45 |
} |