I dun a DIP, possibly the best DIP ever

Nick Treleaven nick at geany.org
Sun May 10 08:30:35 UTC 2020


On Friday, 24 April 2020 at 21:00:08 UTC, Steven Schveighoffer 
wrote:
> import std.algorithm : canFind;
> enum anySatisfy(alias F, T...) = [F!(T)...].canFind(true);
> enum allSatisfy(alias F, T...) = ![F!(T)...].canFind(false);

That might be slower than the existing templates (now in 
core.internal.traits), which don't use template recursion, and 
short circuit:

template anySatisfy(alias F, Ts...)
{
     static foreach (T; Ts)
     {
         static if (!is(typeof(anySatisfy) == bool) && // not yet 
defined
                    F!T)
         {
             enum anySatisfy = true;
         }
     }
     static if (!is(typeof(anySatisfy) == bool)) // if not yet 
defined
     {
         enum anySatisfy = false;
     }
}

Your versions also require an extra import (although canFind 
could be locally copied).


More information about the Digitalmars-d mailing list