On Thu, Mar 08, 2012 at 05:49:20PM +0100, Andrej Mitrovic wrote: > On 3/8/12, H. S. Teoh <hst...@quickfur.ath.cx> wrote: > > foreach (name; __traits(allMembers, typeof(obj))) { > > static if (__traits(compiles, &__traits(getMember, obj, > > name))) > > { > > alias typeof(__traits(getMember, obj, name)) > > type; > > static if (is(type==function)) { > > // name refers to a function of type > > // 'type' here > > } > > } > > } > > > >> I've never had an easy time interacting with __traits. > > Yesterday I've tried the same thing but it didn't work because I was > missing the &__traits call. With that in place, here's a very > hardcoded example of what you can do in D: > > http://paste.pocoo.org/show/562933/ > > So now you can catch the exception if the object was uninitialized. > And you didn't have to modify the target class at all.
Cool! That's a really neat way of doing it. Love the combination of alias this, compile-time introspection, and the awesomeness of D templates. D r0x0rs! T -- Your inconsistency is the only consistent thing about you! -- KD