compile time class introspection?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Thu Jun 14 14:59:21 PDT 2007
serg wrote:
> Max Samukha Wrote:
>> You might do it like this:
>> ...
>> static if (is(typeof(T.OnClose)))
>> ...
>
> Yes, this is exactly what I was looked for!
>
> Thanks, Max!
>
> -- serg.
This is an important thing about D that probably deserves a long and
extensive tutorial somewhere... Many of its cooler features aren't
really features at all, but side-effects of other more general features.
So, to reuse this same example, no D doesn't have a way to ask if a
class or structure has a particular method. D /does/ have a way to
check for valid types... which, incidentally, non-existant members are
invalid types. So, voila, a side-effect of checking its type is that
you confirm it exists.
There are others... a plethora, even. Walter is fond of lots of small
things that can be put together to achieve amazing things -- and I don't
strictly disagree -- but it isn't usually obvious what you can do with
those nifty little gadgets.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list