Ensuring template argument is descendant of class

Ross Hays test at gmail.com
Thu Dec 12 14:05:15 PST 2013


On Thursday, 12 December 2013 at 21:53:20 UTC, Adam D. Ruppe 
wrote:
> On Thursday, 12 December 2013 at 21:51:14 UTC, Ross Hays wrote:
>>        if (cast(Asset)T)
>
> Try this instead:
>
>    if(is(T : Asset))
>
> the is thing checks types. You can do is(T == Asset) for the 
> specific class, or is(T : Asset) which means it implicitly 
> converts to it - in otherworts, if T is Asset or a child of 
> Asset.

Okay thank you, that seems to clear up the error. I found 
http://dlang.org/expression.html#IsExpression and had no idea is 
could be used with that syntax. The more D I learn the more 
counter-intuitive I find some aspects of the language syntax. A 
shame, that was my main point to start using it. Oh well! Thanks


More information about the Digitalmars-d-learn mailing list