opConcatAll?

Steven Schveighoffer schveiguy at gmail.com
Fri Jul 3 17:13:32 UTC 2020


On 7/3/20 11:25 AM, user1234 wrote:
> On Thursday, 2 July 2020 at 19:28:15 UTC, Nick Treleaven wrote:
>> On Thursday, 2 July 2020 at 15:47:39 UTC, Steven Schveighoffer wrote:
>>> a ~ b ~ c ~ d
>>>
>>> will translate to
>>>
>>> a.opConcatAll(b, c, d)
>>
>> Sounds good, although I think multiple other operations beside 
>> concatenation could benefit from being intercepted:
>>
>> opNary(string op, T...)(T args)
>>
>> E.g. perhaps BigInt can avoid one or more reallocations for >2 args. 
>> The compiler would try opNary first in that case, and fallback to 
>> successive calls to opBinary as now.
>>
>> In fact, maybe some types could benefit from intercepting different 
>> operations at once:
>>
>> opNary(string[] ops, T...)(T args)
> 
> Wow, that looked cool the first 3 secons but now I wander if  you really 
> want to let the user break the rules of precedence ?

Meh, the user can do anything he wants already. One can get around 
precedence by deferring calls.

It is true, though, that I didn't think of precedence when I first 
posted -- I just wanted to avoid some allocations.

-Steve


More information about the Digitalmars-d mailing list