xxxxxxxxxx
struct W(T) {
T val;
this(U : T, this This)(auto ref U val) {
this.val = val;
}
}
auto wrap(T)(auto ref T t) {
return W!T(t);
}
class C {}
struct S0 {}
struct S1 { C c; }
void f_dprimitive() {
int a = 3;
const int b = 3;
immutable int c = 3;
const int d = a;
immutable int e = a;
auto sc = wrap!(const int)(3);
auto si = wrap!(immutable int)(3);
}
void f_class() {
W!C a = new C();
const W!C b = new C();
immutable W!(immutable C) c = new immutable C();
const W!C d = a;
// immutable W!C e = a; // cannot implicitly convert mutable to immutable
}
void f_struct() {
W!S0 a = S0();
const W!S0 b = S0();
immutable W!S0 c = S0();
const W!S0 d = a;
immutable W!S0 e = a;
}
void f_struct_with_indirection() {
W!S1 a = S1();
const W!S1 b = S1();
immutable W!(immutable S1) c = immutable S1();
const W!S1 d = a;
// immutable W!S1 e = a; // cannot implicitly convert mutable to immutable
}
void f_wrapper() {
auto a = wrap(new C);
auto b = wrap(new const C);
auto c = wrap(new immutable C);
const W!C d = a;
// immutable W!C e = a; // cannot implicitly convert mutable to immutable
}
void f_wrapper2() {
Object ma = new C();
Object ca = new const C();
Object ia = new immutable C();
auto a = wrap(cast(C)ma);
auto b = wrap(cast(const C)ma);
auto c = wrap(cast(immutable C)ma);
}
void main() {
}