First life-signs of type functions

Stefan Koch uplink.coder at googlemail.com
Sun May 10 10:33:42 UTC 2020


On Sunday, 10 May 2020 at 10:28:17 UTC, Nick Treleaven wrote:
> On Sunday, 10 May 2020 at 08:39:42 UTC, Nick Treleaven wrote:
>>     alias E;
>>     while (S.length)
>>     {
>>         E = S[0];
>>         if (Tem!E)
>>             return true;
>>         S = S[1..$];
>>     }
>>     return false;
>
> I had assumed that indexing an alias[] with a mutable variable 
> wouldn't work. If it does, then I don't even need to mutate S:
>
> bool anySatisfy(alias Tem, alias[] S)
> {
>     size_t i = 0;
>     while (i != S.length)
>     {
>         if (Tem!(S[i]))
>             return true;
>         i++;
>     }
>     return false;
> }
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;
}


More information about the Digitalmars-d mailing list