Question about template argument matching with alias this

Alex sascha.orlov at gmail.com
Mon Jul 30 08:14:52 UTC 2018


On Sunday, 29 July 2018 at 23:03:27 UTC, Johannes Loher wrote:
> Yeah, I know that it possible to implement the template like 
> this, but that is not the point here. I would like to know why 
> it does not work the way I described it. To me it seems very 
> strange, that `S : T` has different semantics in `is` 
> expressions and as template parameters.
>

Yes... I see your point now. It is like "is" itself adds some 
semantics to the colon operator. So, while colon specifies, that 
only derivatives are matched, "is" matches all things, where the 
interface can be extracted...

I think, this is intended:
https://dlang.org/spec/template.html#argument_deduction    p. 5
and
https://dlang.org/spec/expression.html#is_expression    p. 2

But... maybe some native D speaker could comment on this...

> Now I could ask the author of poodinis to remove the 
> restriction on the template parameters for register, but it 
> actually perfectly makes sense to have that restriction, 
> because we are registering a concrete type as an abstract type.

I would say, for practical reasons not to remove the restriction, 
but to formulate it in a more abstract way. This seems to be with 
´if(is(S : T))´ in this case... As otherwise the restriction is 
to use classes only... (?)

> So I am back to my question: Why do we have this strange 
> behavior? All compiler version on run.dlang.io behave like 
> that, so I suppose there is some reason for this...?


More information about the Digitalmars-d-learn mailing list