opConcatAll?
Simen Kjærås
simen.kjaras at gmail.com
Thu Jul 2 21:39:08 UTC 2020
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)
One typical case that this would do great for is BigInt modular
exponentiation (a ^^ b) % c.
One problem with this idea is with order of operations - there's
no way to distinguish (a*b)+c from a*(b+c).
I wrote[0] a suggestion two years ago for something I called
rvalue types, which might be interesting for the use cases
described here. Essentially, it's a type for a temporary value
that will decay to a regular value whenever it's assigned to
something - somewhat like an alias this that is preferred to
using the actual type.
--
Simen
[0]:
https://forum.dlang.org/post/sfvqxnnibgbuebbxweqb@forum.dlang.org
More information about the Digitalmars-d
mailing list