[contest] Is a Cow an animal ++

Simen kjaeraas simen.kjaras at gmail.com
Mon Sep 27 10:20:59 PDT 2010


bearophile <bearophileHUGS at lycos.com> wrote:


> The fourth C++ version contains a line that I am am not even sure how to  
> translate to D (maybe there is a workaround with template constraints):
> (void) static_cast<My_kind *>((Kind *) 0);

This is a static assert of sorts. Basically, the function will only
compile if Kind is a subtype of My_kind. In D, you would use
is( Kind : My_kind ), where Kind and My_Kind are interfaces


Here's mine ( 8/11 at compile-time, the remaining at runtime ):
http://ideone.com/6WlFJ
I don't think it's possible to make it better than that in D without,
as you say, for instance type states.

-- 
Simen


More information about the Digitalmars-d mailing list