First life-signs of type functions

Nick Treleaven nick at geany.org
Sun May 10 10:45:54 UTC 2020


On Sunday, 10 May 2020 at 10:33:42 UTC, Stefan Koch wrote:
> What do you think about this one?
>
> bool anySatisfy(bool function (alias) pred, alias[] types ...)
> {
>     foreach(type; types)
>     {
>         if (pred(type))
>             return true;
>     }
>     return false;
> }

Nice, this makes me wonder if later we'll get type function 
lambdas :-D

I was using `while` instead of foreach because I thought the 
`alias[]` would be treated like a parameter sequence `S...`, and 
so the loop would be inlined. I suppose that wouldn't be bad here 
because your version takes a type function instead of a template 
predicate, so there's no need to avoid instantiating a template 
after the first true result.

I suppose you can define foreach on an alias[] to still work like 
a runtime foreach; that way the loop doesn't have to be inlined. 
(If the programmer wants inlining, use static foreach).


More information about the Digitalmars-d mailing list