Use class template as a type

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 28 15:57:18 PST 2016


On 29/11/2016 3:35 AM, Namespace wrote:
>> We have a handy dandy syntax for this:
>>
>> if (MyClassInt subclass = cast(MyClassInt)value) {
>>     writeln(subclass.value);
>> }
>>
>> If it doesn't cast to said type (it will be null) that branch won't
>> execute.
>
> Just out of interest: it looks like a dynamic_cast in C++ which is
> considered as slow operation. Is that D cast also a dynamic cast and
> also slow? I've never used it, so I'm a bit curious.

I wouldn't worry about it. You're already using classes and they are dog 
slow in general.


More information about the Digitalmars-d-learn mailing list