On type functions

Paul Backus snarwin at gmail.com
Mon May 4 15:55:44 UTC 2020


On Monday, 4 May 2020 at 15:42:01 UTC, Steven Schveighoffer wrote:
> On 5/3/20 5:22 PM, Stefan Koch wrote:
>> On Sunday, 3 May 2020 at 21:14:43 UTC, Max Samukha wrote:
>>> On Sunday, 3 May 2020 at 09:35:34 UTC, Stefan Koch wrote:
>>>
>>>> [...]
>>>
>>> Cool! Does it mean the following will work?
>>>
>>> alias[] map(alias f, alias[] a) {
>>>    alias[] r;
>>>    foreach (e; a)
>>>        r ~= f!e; // can we?
>>>    return r;
>>> }
>>>
>>> enum isType(alias a) = is(a);
>>>
>>> static assert([map!(isType, AliasSeq!(1, int, "meh"))] == 
>>> [false, true, false]);
>> 
>> Yes that's what it means!
>
> I had thought this might work, but I'm not sure.
[...]
> One other thing that is unclear is that map is supposed to take 
> it's list *first* for UFCS. This would have to be different, as 
> variadics typically come at the end of argument lists.
>
> -Steve

If I understand the proposal correctly, it should be ok handle 
UFCS the same way std.algorithm.map does, by taking the function 
as a template argument:

auto map(alias f)(alias[] a) {
     // etc
}


More information about the Digitalmars-d mailing list