I dun a DIP, possibly the best DIP ever

Mafi mafi at example.org
Thu Apr 23 17:44:44 UTC 2020


On Thursday, 23 April 2020 at 16:40:05 UTC, Steven Schveighoffer 
wrote:
> On 4/23/20 11:39 AM, Mafi wrote:
>> 
>> Well, then what about:
>> 
>> template crossHelper(alias F, X, Y...) {
>>    alias crossHelper = F!(X, Y)...;
>> }
>> 
>> crossHelper!(S, X, Y...)...
>
> In this call, Y... does nothing, it just trivially means Y, so 
> you really have:

This is wrong under the assumption I wrote before: nested 
...-expressions are expanded first!

To explain in more detail what I mean: Let A be the sequence 
(101, 102, 103) and B be (201, 202, 203). Then F!(A, B)... is 
(F!(101, 201), F!(102, 202), F!(103, 203)) analoguous to 
simultaneous expansion in C++ and as explained in the DIP draft.

But of course:

F!(A, B[0], B[1], B[2])... is (F!(101, 201, 202, 203), F!(102, 
201, 202, 203), F!(103, 201, 202, 203))

So if ...-expansions are expanded inside out then:

F!(A, B...)... is F!(A, B[0], B[1], B[2])... is (F!(101, 201, 
202, 203), F!(102, 201, 202, 203), F!(103, 201, 202, 203))

this can exploited to implement cross product using my helper I 
wrote above.



More information about the Digitalmars-d mailing list