Some astonishment [Re: static foreach]
bearophile
bearophileHUGS at lycos.com
Sun Mar 28 15:34:50 PDT 2010
so:
> Reading it again, how i missed page 34, awesome!
Page 6 is about The Rule of Least Astonishment, D tries hard (and often succeeds) to be uniform, to do the same things when you use the same syntax in different parts of the language.
But I have hitted a case, "T : T*" can mean different things when used in a template or in a is():
template IsPointer1(T : T*) {
enum bool IsPointer1 = true;
}
template IsPointer1(T) {
enum bool IsPointer1 = false;
}
template IsPointer2(T) {
enum bool IsPointer2 = is(T : T*);
}
void main() {
static assert(IsPointer1!(int*));
static assert(IsPointer2!(int*)); // asserts
}
This is a dis-uniformity. I have found it only years of using D1, and it has caused me few troubles.
Bye,
bearophile
More information about the Digitalmars-d
mailing list