I dun a DIP, possibly the best DIP ever

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 23 18:05:07 UTC 2020


On 4/23/20 1:44 PM, Mafi wrote:
> 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.
> 

What you are asking for is that B is expanded into "not-a-tuple" before 
the outer expression is expanded. I don't think that's the plan, I think 
SomeTuple... expands to SomeTuple.

What I think the DIP is going to do is expand B first into a tuple, and 
then that tuple is now expanded the same as F!(A, B)....

But maybe I'm wrong? For sure more clarification is needed on nested 
expansion.

-Steve


More information about the Digitalmars-d mailing list