opConcatAll?

Timon Gehr timon.gehr at gmx.ch
Fri Jul 3 14:35:25 UTC 2020


On 02.07.20 21:28, 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)

Maybe it could pass a single fully parenthesized expression instead of 
an array of operators.

But given D's philosophy of crippling operator overloading in the name 
of prevention of "abuse", something like this will likely never be added.


More information about the Digitalmars-d mailing list