I dun a DIP, possibly the best DIP ever

Steven Schveighoffer schveiguy at gmail.com
Sat May 9 16:26:42 UTC 2020


On 5/9/20 11:28 AM, Timon Gehr wrote:
> On 24.04.20 23:00, Steven Schveighoffer wrote:
>> On 4/24/20 4:15 PM, Walter Bright wrote:
>>
>>>
>>> Since then it's an array, use the existing array folding methods.
>>
>> This is probably good enough, because we can generate arrays at 
>> compile-time and process them via CTFE.
>>
>> Some key targets within std.meta are anySatisfy/allSatisfy.
>>
>> A quick stab at this (I'm going to stick with the ellipsis version as 
>> it's easy to ):
>>
>> import std.algorithm : canFind;
>> enum anySatisfy(alias F, T...) = [F!(T)...].canFind(true);
>> enum allSatisfy(alias F, T...) = ![F!(T)...].canFind(false);
>>
>> Wow, that reads so clean.
>>
>> I'm so in love with this feature, when can we get it in?
>>
> 
> This is not equivalent to the current implementations.
> 
> import std.meta;
> 
> enum Foo(int x)=true;
> // true now, but compile error with your approach:
> pragma(msg, anySatisfy!(Foo, 1, int));

I'm not sure I'd call that a "feature" though, or just invalid input:

pragma(msg, anySatisfy!(Foo, int, 1)) => error.

This should provide the best situation I think:

template evalBool(alias F, V...) if (V.length == 1){
     static if(is(typeof(F!V) == bool))
       enum evalBool = F!V;
     else
       enum evalBool = false;
}

enum anySatisfy(alias F, T...) = [evalBool!(F, T)...].canFind(true);

-Steve


More information about the Digitalmars-d mailing list