simple question about UFCS and templates...wasFound(i) works but not i.wasFound()
monkyyy
crazymonkyyy at gmail.com
Wed Mar 19 23:21:15 UTC 2025
On Wednesday, 19 March 2025 at 22:26:54 UTC, WhatMeWorry wrote:
> ```
> bool wasFound(I)(I result)
> {
> return(result != -1);
> }
>
> bool existPoint(Point b, int cost)
> {
> auto i = closed.countUntil(b);
>
> if(wasFound(i)) // -1 is returned if no point b is
> found in the range
> ```
>
> The above compiles and executes successfully. But the following
> fails with:
> app.d(179,13): Error: no property `wasFound` for `i` of type
> `long`
>
> I thought the templated function would take care of any type.
> ```
> bool wasFound(I)(I result)
> {
> return(result != -1);
> }
>
> bool existPoint(Point b, int cost)
> {
> auto i = closed.countUntil(b); // Note: closed
>
> if(i.wasFound()) // -1 is returned if no point b is
> found in the range
> ```
ufcs on local functions is hit or miss; theres a old limitation
that d1 wanted or something; ussally templates do fix it but
without full context its hard for me to tell the exact reason.
More information about the Digitalmars-d-learn
mailing list