How do I make a template function that only accepts instances of a specific class?

Jack jckj33 at gmail.com
Mon Jan 18 22:40:08 UTC 2021


On Monday, 18 January 2021 at 19:54:04 UTC, Adam D. Ruppe wrote:
> On Monday, 18 January 2021 at 19:34:52 UTC, Jack wrote:
>> is that sytax derived from there?
>
> sort of. it is the type pattern matching "is expression" 
> described here:
>
> https://dlang.org/spec/expression.html#IsExpression

I read std.traits and some related stuff but missed reading is 
expression doc lol

>
> The is(A:B) thing technically means "if A is implicitly 
> convertible to B" which of course works for base classes and 
> interfaces well but that's not all it does, like is(int : long) 
> passes too.

C# uses something like that too but I totally missed to look for 
the equivalent in D, which would be pretty much same thing

> I just remember the syntax thanks to its similarity to type 
> declarations.

good way to remember too



More information about the Digitalmars-d-learn mailing list