Template type inference problem

Timon Gehr timon.gehr at gmx.ch
Thu Oct 3 00:34:28 UTC 2024


On 10/2/24 10:55, Manu wrote:
> Does anyone understand why this doesn't work?
> 
> void f(T)(const(T)[] x, const(T)* y) {}
> void test()
> {
>      int*[] x;
>      const int* y;
>      f(x, &y);
> }
> 
> error : template `f` is not callable using argument types `!()(int*[], 
> const(int*)*)`
>          Candidate is: `f(T)(const(T)[] x, const(T)* y)`
> 
> Should this work? It looks like it should work to me.
> ...assuming T is inferred to be `int*`... which it's not clear why it 
> wouldn't be?
> 
> The argument `y` is an exact match. The argument `x` requires a const 
> promotion, and then T can be inferred correctly. Perhaps it's the order 
> of that operation that it can't deal with?
> 
> I kinda reckon this is a bug...

Yes, I think it should work.


More information about the Digitalmars-d mailing list