Typeof woes
Marek Janukowicz
marek at janukowicz.net
Tue Aug 20 23:40:00 PDT 2013
Andrej Mitrovic wrote:
> On 8/21/13, H. S. Teoh <hsteoh at quickfur.ath.cx> wrote:
>> and typeof(this.Smth) is invalid because this.Smth is already a
>> type, so you can't apply typeof to it.
>
> I am beginning to wonder if typeof(typeof(expr)) is worthy of an
> error. Would we end up having any bugs if we were to allow typeof() to
> work on types (IOW it would just alias itself to the type)?
It's not always considered an error, this code compiles fine (my guess is
the "is" expression does some magic with its arguments):
import std.stdio;
class A {
int a;
enum Smth { A };
void list () {
foreach( s; __traits(derivedMembers, typeof(this))) {
static if (is (typeof(typeof(typeof(__traits(getMember, this, s)))) ==
int)) {
writefln ("%s is int", s );
}
}
}
}
void main () {
A a = new A();
a.list();
}
--
Marek Janukowicz
More information about the Digitalmars-d-learn
mailing list