simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

H. S. Teoh hsteoh at qfbox.info
Wed Mar 19 23:10:06 UTC 2025


On Wed, Mar 19, 2025 at 10:26:54PM +0000, WhatMeWorry via Digitalmars-d-learn wrote:
[...]
> 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
> ```

Where is wasFound declared?  If you want UFCS syntax to work, wasFound
must be declared in global (module) scope. Otherwise, it will not be
considered for UFCS when resolving identifiers.


T

-- 
The cat owns the house; that's why the word "homeowner" has "meow" in it.


More information about the Digitalmars-d-learn mailing list