On Saturday, 7 December 2013 at 01:18:06 UTC, Ellery Newcomer
wrote:
On 12/05/2013 09:33 PM, Jesse Phillips wrote:
I don't think I understand what you mean:
this code illustrates it:
class Z {
string a() immutable {
return " 1";
}
string b() {
return "2";
}
}
template F(t) {
alias immutable(t) F;
}
alias typeof(&Z.init.a) Texpected;
alias typeof(&Z.init.a) T;
static assert(is(F!(T) == Texpected));
void main() {}
above F doesn't work; immutable(void delegate()) and void
delegate() immutable are different types (I think the latter
means 'this' is immutable).
If t were a function pointer, you would apply the immutable to
the pointer target like so:
alias immutable(pointerTarget!t)* F
This declaration doesn't make sense to me:
string a() immutable {
return " 1";
}
'a' is already immutable (unless you consider the vtable, at
which point: final string a(); would be immutable).
The compiler spits out: static assert (is(immutable(string
delegate()) == string delegate() immutable)) is false
Which is strange because I don't see how immutability on 'a'
means anything. And because of this I think your assertion is
wrong:
static assert(is(F!(T) == Texpected));
Is basically asking
static assert(is(immutable(int) == int));
Which is not true, but this is (I've made modifications to your
code):
class Z {
string a() {
return " 1";
}
string b() {
return "2";
}
}
template F(t) {
alias immutable(t) F;
}
alias typeof(&Z.init.a) Texpected;
alias typeof(&Z.init.b) T;
static assert(is(immutable(int) : int)); // Implicitly converts to
static assert(is(int : immutable(int))); // Implicitly converts to
static assert(is(F!(T) : Texpected)); // Implicitly converts to
static assert(is(Texpected : F!(T) )); // Implicitly converts to
void main() {}