Dynamic templated virtuals - I still often want them

Steven Schveighoffer schveiguy at gmail.com
Thu Jul 23 17:40:50 UTC 2020


On 7/23/20 1:09 PM, Adam D. Ruppe wrote:
>> One other tricky thing is that the override functions must not vary 
>> the parameter or return types (except for covariance).
> 
> Yeah, it would still be subject to the same semantic checks as if it was 
> written by hand and would need to error there; it is still an interface 
> method. Though the compiler might not actually diagnose that error until 
> you actually try to subclass it (again, just like the mixin template 
> thing, just without the explicit `mixin X`).

It might be trickier than that. It might be that you have to ENSURE that 
there's only one version of the function to override. Otherwise, you can 
have an unbounded requirement for the vtable.

e.g.:

void foo(this This, T)(T item) {... }

As this is valid today, we can't (and shouldn't) disallow it. But it 
also can't be virtual.

It means we might have to require a separate syntax for this feature. An 
actual virtual keyword would be super-useful here.

-Steve


More information about the Digitalmars-d mailing list