Template type inference problem

Manu turkeyman at gmail.com
Wed Oct 9 07:02:32 UTC 2024


On Sat, 5 Oct 2024 at 10:26, Salih Dincer via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Wednesday, 2 October 2024 at 08:55:15 UTC, Manu wrote:
> > Does anyone understand why this doesn't work?
> > ```d
> > 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.
>
> Hi Manu, what did you do, any progress? So why don't you use 2
> aliases like T, R? For example:
>
> ```d
> template func(T : const T, R : const R)
> {
>    void func(const(T)[] x, const(R)* y)/*
>    void func(T[] x, R* y)//*/
>    {
>      typeid(x).writeln(": ", T.stringof);
>      typeid(y).writeln(": ", R.stringof);
>    }
> }
>
> import std.stdio;
> void main()
> {
>    const
>        int[] x;
>    //const
>        int y;
>
>    func(x, &y); /* Output:
>         const(int)[]: int
>         const(int)*: int  */
>
>    const
>        int* [] a;
>    //const
>        int* b;
>
>    func(a, &b); /* Output
>         const(const(int)*)[]: const(int)*
>         const(const(int)*)*: int*  */
> }
> ```
>
> SDB79
>


I did nothing. I just did work-around and moved on... but I think this is
definitely a bug.
Just another random edge case in a sea of annoying edge cases! :P
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20241009/d9ecd4fd/attachment.htm>


More information about the Digitalmars-d mailing list